簡體   English   中英

Tkinter如何使用按鈕隱藏當前窗口並打開新窗口

[英]Tkinter how to use a button to hide current window and open new one

我試圖使用一個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()

您可以嘗試如下操作:

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()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM