Python tkinter如何将框架分成几个部分?
我正在制作TkinterGUI程序。在程序中,当我单击按钮时,会显示一个弹出窗口。 我想将弹出框分成9个按钮,并在按钮中显示图像。 但在我的代码中,按钮是连接的,而不是分开的。 下面是我代码的一部分。我会等待你的帮助。多谢各位Python tkinter如何将框架分成几个部分?,python,button,tkinter,Python,Button,Tkinter,我正在制作TkinterGUI程序。在程序中,当我单击按钮时,会显示一个弹出窗口。 我想将弹出框分成9个按钮,并在按钮中显示图像。 但在我的代码中,按钮是连接的,而不是分开的。 下面是我代码的一部分。我会等待你的帮助。多谢各位 def create_window(self): window=Toplevel(root2) window.geometry("600x600") self.galleryframe=Frame(window)
def create_window(self):
window=Toplevel(root2)
window.geometry("600x600")
self.galleryframe=Frame(window)
self.galleryframe.pack()
self.topgframe=Frame(self.galleryframe,width=600,height=200)
self.topgframe.pack()
self.ibutton1=Button(self.topgframe,width=20,height=20)
try:
self.image1=PhotoImage(file="/home/som/imagefolder/1.png")
self.ibutton1.config(image=self.image1)
self.ibutton1.image=self.image1
except TclError:
pass
self.ibutton1.pack(side=LEFT)
self.ibutton2=Button(self.topgframe,width=20,height=20)
try:
self.image2=PhotoImage(file="/home/som/imagefolder/2.png")
self.ibutton2.config(image=self.image2)
self.ibutton2.image=self.image2
except TclError:
pass
self.ibuttom2.pack()
self.ibutton3=Button(self.topgframe,width=20,height=20)
try:
self.image3=PhotoImage(file="/home/som/imagefolder/3.png")
self.ibutton3.config(image=self.image3)
self.ibutton3.image=self.image3
except TclError:
pass
self.ibuttom3.pack(side=RIGHT)
self.midgframe=Frame(self.galleryframe,width=600,height=200)
self.midgframe.pack()
self.ibutton4=Button(self.midgframe,width=20,height=20)
try:
self.image4=PhotoImage(file="/home/som/imagefolder/4.png")
self.ibutton4.config(image=self.image4)
self.ibutton4.image=self.image4
except TclError:
pass
self.ibuttom4.pack(side=LEFT)
....ibutton5-9 are almost same with upper things.
您的代码中有一个小的输入错误。尝试替换:
self.ibuttom2.pack()
与
如果问题是由简单的印刷错误引起的,请评论错误并标记为“简单印刷错误”@abccd,好的,我会这样做!
self.ibutton2.pack() # Same for buttons 3, 4, etc.