使用.get()时Tk.entry返回空白

时间:2018-12-09 11:34:04

标签: python tkinter

我的大学课程遇到麻烦。我无法让我的程序将tk.entry中的输入传递给另一个函数。有什么想法吗?

功能如下:

def maintest():

global studentans
global questions
global pointer
questiontitle = str(questions[pointer][0])
questionmarks = str(questions[pointer][1])
marktitle = ("this question is " + questionmarks + " marks")

test = Tk()
test.configure(bg=white)
test.attributes("-fullscreen", True)
test.title("Student Register")
test.configure(bg=white, padx=20, pady=20)

username = StringVar()

tk.Label(test, text=questiontitle, font=("Calibri", 40), fg=black, bg=white).place(relx=0.5, rely=0.1,
                                                                                   anchor=CENTER)
tk.Label(test, text=marktitle, font=("Calibri", 20), fg=black, bg=white).place(relx=0.5, rely=0.2, anchor=CENTER)

tk.Entry(test, width=50, bg=grey, textvariable=username,
         font=("Calibri", 25)).place(relx=0.5, rely=0.3, anchor=CENTER)

tk.Button(test, text="SUBMIT", font=("Calibri", 12),
          command=lambda: openans(username.get(), test),
          height=5, width=50, bg=grey, fg=black, borderwidth=0).place(relx=0.5, rely=0.7, anchor=CENTER)
tk.Button(test, text="MAIN MENU", font=("Calibri", 12),
          command=lambda: return_login(test), height=5, width=50, bg=grey, fg=black, borderwidth=0).place(relx=0.5,
                                                                                                          rely=0.9,
                                                                                                          anchor=CENTER)
test.mainloop()

0 个答案:

没有答案