好的,这是我的问题:
下面的代码,当被按钮调用时,会打印NOTHING。为什么?(是的,我当然是在输入框中输入内容。)
options = Tk()
options.geometry("218x156")
options.iconbitmap('original.ico')
options.title("Options")
Label(options, text = "GitHub Username:").pack()
userName = StringVar()
Entry(options, width = "30", textvariable = userName).pack()
Label(options, text = "GitHub Email:").pack()
userEmail = StringVar()
Entry(options, width = "30", textvariable = userEmail).pack()
Label(options, text = "GitHub Password:").pack()
userPassword = StringVar()
Entry(options, show = "•", width = "30", textvariable = userPassword).pack()
def optionSave():
print(userName.get())
print(userEmail.get())
print(userPassword.get())
options.destroy()
工作,和
def fileOptions():
options = Tk()
options.geometry("218x156")
options.iconbitmap('original.ico')
options.title("Options")
Label(options, text = "GitHub Username:").pack()
userName = StringVar()
Entry(options, width = "30", textvariable = userName).pack()
Label(options, text = "GitHub Email:").pack()
userEmail = StringVar()
Entry(options, width = "30", textvariable = userEmail).pack()
Label(options, text = "GitHub Password:").pack()
userPassword = StringVar()
Entry(options, show = "•", width = "30", textvariable = userPassword).pack()
def optionSave():
print(userName.get())
print(userEmail.get())
print(userPassword.get())
options.destroy()
才不是
请注意:唯一明显的区别是代码
底部没有包裹它def fileOptions():
输出为空白。因为它将zilch打印到控制台。这是因为它在一个单独的窗口中吗?如果是这样,我该如何解决?