[英]input box does not appear in tkinter window
我對 tkinter 有疑問。 基本上當我嘗試創建一個輸入框時,window 僅以標題打開。
from tkinter import *
window = Tk()
window.title("name generator")
def openInterface():
inputLabel = Label(window, text="Enter your name")
inputLabel.grid(row=0, column=2)
print(inputLabel)
我錯過了什么嗎? 我為此提前道歉,這是一個菜鳥問題。
你永遠不會調用你的openInterface
function。 函數與全局 scope 中的代碼不同,因為它們僅在調用時執行,而不是在定義時執行。
from tkinter import *
window = Tk()
window.title("name generator")
openInterface()
def openInterface():
inputLabel = Label(window, text="Enter your name")
inputLabel.grid(row=0, column=2)
print(inputLabel)
我認為您缺少兩件事,您沒有調用功能,而且您還需要使用
window.mainloop()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.