簡體   English   中英

Python Tkinter window 神秘地沒有打開

[英]Python Tkinter window mysteriously not opening

由於某種原因,以下簡單的 Python 程序對我來說失敗了:

from tkinter import *
print("Submit the following form:")
a = str(input("Have you registered before? (y/n) "))
if a == 'y':
    root = Tk()
else:
    # Code path for unregistered users, not relevant to the question.
    pass

在程序運行時鍵入y不會執行任何操作,Tkinter window 永遠不會打開。

您忘記在代碼中添加root.mainloop() 嘗試這個:

from tkinter import *
print("Submit The Form")
a=str(input("Have You Registered Before?(y/n)"))
if a=='y':
    root=Tk()
    #your code
    root.mainloop()
else:
    pass

希望能幫助到你!

暫無
暫無

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

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