我正在尝试使用一个tkinter按钮,该按钮在单击时会打开另一个窗口,并隐藏其中带有该按钮的当前窗口。
def game():
window = tk.Toplevel()
window.geometry("1280x720")
root = tk.Tk()
root.title('testgame')
root.resizable(False,False)
root.geometry("500x500")
pbutton = tk.Button(root, text='Play', width=25, command=game and root.withdraw).place(relx = 0.5,rely = 0.5, anchor = 'center')
root.mainloop()
答案 0 :(得分:0)
您可以尝试以下操作:
import tkinter as tk
root = tk.Tk()
#In order to hide main window
root.withdraw()
tk.Label(root, text="Main Window").pack()
aWindow = tk.Toplevel(root)
def change_window():
#remove the other window entirely
aWindow.destroy()
#make root visible again
root.iconify()
root.deiconify()
tk.Button(aWindow, text="This is aWindow", command=change_window).pack()
root.mainloop()