我在窗口上做了3个按钮。我选择了主窗口应该有一个特定的背景图像和全屏。python tkinter点击按钮打开新窗口
现在出现了问题。我想通过点击按钮3.
事情我tryd移动到一个新的窗口(页)(与其他背景和其他的东西):
从Main.Info.travelhistry进口*
我已将此添加到主窗口中打开,具有在按钮3.点击时,但我发现,打开第二个屏幕的代码的新的Python的文件,如果我这样做既Windows会运行主窗口时打开。
我在开头添加了root1 = Tk(),在末尾添加了root1.mainloop(),并在它们之间添加了另一个窗口的代码。但是这样做也不起作用,它像上面那样开放2个窗口。
这些都是我的尝试,我不能找出更好的方法。我可以但背景保持不变。但我必须将新窗口的背景更改为我制作的背景图片...
任何想法我做错了什么?
from tkinter import *
from tkinter.messagebox import showinfo
from Main.Info.travelhistry import *
def clicked1():
bericht = 'Deze functie is uitgeschakeld.'
showinfo(title='popup', message=bericht)
root = Tk()
a = root.wm_attributes('-fullscreen', 1)
#Hoofdmenu achtergrond
C = Canvas(root, bg="blue", height=250, width=300)
filename = PhotoImage(file = "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="button1.png")
b.config(image=photo,width="136",height="53", background='black')
b.place(x=310, y=340)
#Buitenland button
b2=Button(master=root, command=clicked1)
photo1=PhotoImage(file="button2.png")
b2.config(image=photo1,width="136",height="53", background='black')
b2.place(x=490, y=340)
#Reis informatie
b3=Button(master=root)
photo2=PhotoImage(file="button3.png")
b3.config(image=photo2,width="136",height="53", background='black')
b3.place(x=680, y=340)
root.mainloop()
root2.mainloop()
+1
目前尚不清楚,从你的描述,但你是不是想开多个根'TK()'窗口,你是谁?你不应该那样做:'Tk()'调用不仅仅是打开一个窗口,而是附加了一个Tcl解释器的实例,你应该只有一个!如果你需要更多的窗户,你需要使用Toplevel窗户。 –
+0
是的,我试图打开其中的两个,它同时开放工作。我不想让我只想点击按钮3后打开第二个Tk。我将搜索Toplevel教程。我从来没有听说过它。 –