«Анкета», на которую есть ссылки перед заданием в формате Tkinter - PullRequest
0 голосов
/ 02 марта 2019

Я хотел сделать отдельный вопрос, который не будет отклоняться от оригинальной темы (учитывая отрицательные отзывы, которые у него были из-за моего невнимания к правилам форума)

По какой-то странной причине я сделалновое окно с именем 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

Если возможно (или даже имеет право), не могли бы вы помочь?

1 Ответ

0 голосов
/ 02 марта 2019

Отдельное спасибо Мартино и Джейсонхарперу!Выяснилось, что Анкета уже была определена как кнопка, которая, как вы можете видеть ...

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()

Мне просто пришлось переименовать одну из кнопок

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...