【发布时间】:2018-04-03 05:12:55
【问题描述】:
我正在使用 tkinter 开发 GUI。 我有一个主菜单,在这个菜单里面有三个按钮。我想通过单击按钮 3 打开一个新窗口。现在在我的代码中它正在做我几乎想要的事情。但是正如你所看到的,我在按钮 3 中添加了一个命令来破坏主根以转到第二个。 但这会导致问题,例如:当我想关闭主菜单时,它会自动打开第二个根。我只是尝试发挥创意,因为我找不到另一种方法来打开具有不同背景图像的新窗口。 我可以用来让生活更轻松的任何想法、技巧或功能吗? 我的代码:
from tkinter import *
from tkinter.messagebox import showinfo
def clicked1():
bericht = 'Deze functie is uitgeschakeld.'
showinfo(title='popup', message=bericht)
root = Tk()
def quit():
root.destroy()
a = root.wm_attributes('-fullscreen', 1)
#full screen
#w, h = root.winfo_screenwidth(), root.winfo_screenheight()
#root.geometry("%dx%d+0+0" % (w, h))
#Hoofdmenu achtergrond
C = Canvas(root, bg="blue", height=250, width=300)
filename = PhotoImage(file="C:\\Users\\Downloads\\test1.png")
background_label = Label(root, image=filename)
background_label.place(x=0, y=0, relwidth=1, relheight=1)
C.pack()
# Geen OV-chipkaart button
b=Button(master=root, command=clicked1)
photo=PhotoImage(file="C:\\Users\\Downloads\\button1.png")
b.config(image=photo,width="136",height="53", background='black')
b.place(x=310, y=340)
#exit button
exitbut = PhotoImage(file = "C:\\Users\\Downloads\\exit1.png")
starter = Label(image = exitbut)
starter.pack()
start = Label(image = exitbut)
start.place(x=900, y=140)
#Buitenland button
b2=Button(master=root, command=clicked1)
photo1=PhotoImage(file="C:\\Users\\Downloads\\button2.png")
b2.config(image=photo1,width="136",height="53", background='black')
b2.place(x=490, y=340)
#Reis informatie
b3=Button(master=root, command=quit)
photo2=PhotoImage(file="C:\\Users\\Downloads\\button3.png")
b3.config(image=photo2,width="136",height="53", background='black')
b3.place(x=680, y=340)
root.mainloop()
#2e window-------------------------------------------------------------
root2 = Tk()
#full screen
a = root2.wm_attributes('-fullscreen', 1)
#achtergrond
D = Canvas(root2, bg="blue", height=250, width=300)
filename = PhotoImage(file = "C:\\Users\\Downloads\\leeg.png")
background_label = Label(root2, image=filename)
background_label.place(x=0, y=0, relwidth=1, relheight=1)
D.pack()
# Geen OV-chipkaart button
c1=Button(master=root2, command=clicked1)
photo3=PhotoImage(file="C:\\Users\\Downloads\\mijnlocatie.png")
c1.config(image=photo3,width="136",height="53", background='black')
c1.place(x=210, y=70)
# Geen OV-chipkaart button
c2=Button(master=root2, command=clicked1)
photo4=PhotoImage(file="C:\\Users\\Downloads\\overigelocaties.png")
c2.config(image=photo4,width="136",height="53", background='black')
c2.place(x=210, y=140)
root2.mainloop()
【问题讨论】:
标签: python user-interface tkinter