我想提出一个不会偏离原始主题的单独问题(由于我对论坛规则缺乏关注而给出了支持)
出于某种奇怪的原因,我创建了一个名为Questionnaire
的新窗口:
def Questionnaire():
quiz_page = Tk()
quiz_page.title('Questionnaire')
quiz_page.geometry('600x350')
greet = Label(quiz_page, text='Welcome to the questionnaire! You will '
'answer a few questions to produce a result '
'for both you and your teacher to see!')
greet.grid(row=0,column=0)
然后我将该函数称为学生登录页面。
def student_menu():
#student_login.destroy()
student_page = Tk()
student_page.title('Hello student')
student_page.geometry('300x130')
Welcome_msg = Label(student_page, text='Welcome').pack()
Questionnaire = Button(student_page,text='Quiz',command=Questionnaire).pack()
View = Button(student_page,text='View',command=view).pack()
但是当我登录应用程序时,我得到一个没有按钮的窗口,这个错误。
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\Hassan Nur\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 1705, in __call__
return self.func(*args)
File "C:\Users\Hassan Nur\Documents\Python - Programming Project\Project\Python Project\Python Project.py", line 78, in student_confirm
student_menu()
File "C:\Users\Hassan Nur\Documents\Python - Programming Project\Project\Python Project\Python Project.py", line 107, in student_menu
Questionnaire = Button(student_page,text='Quiz',command=Questionnaire).pack()
UnboundLocalError: local variable 'Questionnaire' referenced before assignment
如果可能(甚至符合条件),您能帮忙吗?
特别感谢martineau和jasonharper!发现调查问卷已被定义为按钮,您可以看到......
def student_menu():
#student_login.destroy()
student_page = Tk()
student_page.title('Hello student')
student_page.geometry('300x130')
Welcome_msg = Label(student_page, text='Welcome').pack()
Question = Button(student_page,text='Quiz',command=Questionnaire).pack()
View = Button(student_page,text='View',command=view).pack()
我只需要重命名其中一个按钮