我在窗户上制作了3个按钮。我选择主窗口应该有一个特定的背景图像和一个全屏幕。
现在有一个问题。我想通过点击按钮3移动到一个新窗口(页面)(带有其他背景和其他东西)。
我尝试过的事情:
我在开头添加了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()
答案 0 :(得分:0)
您不应该拨打多个Tk()
窗口。
相反,tkinter有另一个名为Toplevel
的小部件,可用于生成新窗口。
见下面的例子:
from tkinter import *
root = Tk()
def command():
Toplevel(root)
button = Button(root, text="New Window", command=command)
button.pack()
root.mainloop()
答案 1 :(得分:0)
这将打开一个您可以编辑的新窗口。
from tkinter import *
Window = Tk()
def Open():
New_Window = Tk()
#You can edit here.
New_Window.mainloop()
Btn1 = Button(text="Open", command=Open)
Bt1n.pack()
Window.mainloop()