我希望用户单击按钮后输入一个值。我试图在单击按钮的函数中定义条目,但是什么也没出现?单击按钮时,标签会发生变化,具体情况与我在功能中对其配置的含义相同,但没有出现该条目。
def jan():
Birth_Month = "January"
January.forget()
February.forget()
March.forget()
April.forget()
May.forget()
June.forget()
July.forget()
August.forget()
September.forget()
October.forget()
November.forget()
December.forget()
Title.configure(text="So you were born in January")
Month.configure(text="What date in January?")
Date = tkinter.Entry(window)
Birth_Date = Date.get()
Birth_Date = Birth_Date.int()
答案 0 :(得分:2)
要显示小部件,需要在对象上使用几何管理器之一(pack
,grid
,place
)。
Date = tkinter.Entry(window)
Date.pack() # or grid, place depending on rest of your code
此外,为了不每次都创建 new Entry
,您应该在函数的全局范围外创建Entry
,并在函数内部pack
中创建
Date = tkinter.Entry(window) # somewhere in your code that is accessible to your method
def jan():
Date.pack()