分配前以Tkinter格式引用的“问卷”

时间:2019-03-02 15:48:00

标签: python python-3.x tkinter

我想提出一个单独的问题,它不会偏离原始主题(考虑到由于我对论坛规则缺乏关注而产生的反对意见)

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

但是当我登录该应用程序时,出现一个没有按钮的窗口,并且出现此错误。

import { createBrowserHistory } from "history";

如果可能(甚至有资格),请您帮忙?

1 个答案:

答案 0 :(得分:0)

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

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