简体   繁体   English

tkinter window中没有出现输入框

[英]input box does not appear in tkinter window

I have an issue with tkinter.我对 tkinter 有疑问。 Basically When I attempt to create an input box, the window opens with the title only.基本上当我尝试创建一个输入框时,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)

Am i missing something?我错过了什么吗? My apologies in advance for this is a noob question.我为此提前道歉,这是一个菜鸟问题。

You never call your openInterface function.你永远不会调用你的openInterface function。 Functions are different from code in the global scope becasue they only get executed when called, not when they are defined.函数与全局 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)

I think you are missing two things, you haven't call funtion and also you you need to use我认为您缺少两件事,您没有调用功能,而且您还需要使用

window.mainloop()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM