简体   繁体   中英

input box does not appear in tkinter window

I have an issue with tkinter. Basically When I attempt to create an input box, the window opens with the title only.

 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. Functions are different from code in the global scope becasue they only get executed when called, not when they are defined.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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