作业前以Tkinter表格引用的“调查问卷”

2024-04-23 15:21:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我想提出一个独立的问题,它不会偏离原来的思路(考虑到由于我对论坛规则缺乏关注而导致的反对票)

出于某种奇怪的原因,我创建了一个名为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

如果可能(甚至有资格),你能帮忙吗


Tags: totextinprojectpagebuttonquizusers
1条回答
网友
1楼 · 发布于 2024-04-23 15:21:46

特别感谢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()

我只需重新命名其中一个按钮

相关问题 更多 >