【发布时间】:2019-06-03 12:27:06
【问题描述】:
这是我的第一篇文章,所以我希望我没有做错任何事情。
目标:
我的目标是制作一个有 4 个按钮的菜单。此框架应仅显示这 4 个按钮。所有按钮都必须适合动态框架。
这是主程序:
class Tab_View(ttk.Frame):
def __init__(self, parent, *args, **kwargs):
self.frame_ini = tk.Frame(self.parent, bg=bg_1)
self.frame_ini.place(relwidth=1, relheight=1)
self.btn1= tk.Button(self.frame_ini, image=self.image_button1, cursor="hand2")
self.btn2= tk.Button(self.frame_ini, image=self.image_button2, cursor="hand2")
self.btn3= tk.Button(self.frame_ini, image=self.image_button3, cursor="hand2")
self.btn4= tk.Button(self.frame_ini, image=self.image_button4, cursor="hand2")
# Putting all the buttons in the frame
self.btn1.pack(expand = True, fill='both')
self.btn2.pack(expand = True, fill='both')
self.btn3.pack(expand = True, fill='both')
self.btn4.pack(expand = True, fill='both')
if __name__ == '__main__':
root = tk.Tk()
root.minsize(900,400)
frame(root)
root.mainloop()
这显示了框架中的所有按钮,但问题在于附加到按钮的图像似乎比按钮本身小。
我尝试过使用resize,但是当我最大化框架时,这些图片没有更新,因此它们不适合。
我期待这个: (https://i.gyazo.com/c52fbda518594ceec0ec1cebe0baedd7.png)
但图像必须根据屏幕大小改变大小。 你能告诉我一个更好的解决方案吗?
谢谢大家! 我希望我已经很好地表达了自己。
【问题讨论】:
标签: python image button tkinter