Я пытаюсь закрыть окно, а затем открыть новое окно в классе, но второе окно не открывается.
Может кто-нибудь сказать мне, что не работает.
(код делаетигра, которая получает случайные 2 числа и просит вас сложить их вместе, затем выводит сообщение о том, правы вы или нет)
Код в своем собственном окне, а не в классе, работает.
Self.G - это экран главного меню.
Код здесь:
def start(self):
self.G.destroy()
self.game()
## The game playing ##
def game(self):
def Questions(self):
number1 = random.randrange(1,25)
number2 = random.randrange(1,50)
answer = number1 + number2
prompt = ("Add " + str(number1) + " and " + str(number2))
label1 = Label(self.root, text=prompt, width=len(prompt), bg='yellow')
label1.pack()
return answer
def start(self):
global answer
answer = Questions()
def Submit(answer, entryWidget):
""" Display the Entry text value. """
print(answer)
if entryWidget.get().strip() == "":
messagebox.showerror("Tkinter Entry Widget", "Please enter a number.")
if answer != int(entryWidget.get().strip()):
incorrect = ('Thats incorrect!')
boxInco = Label(root, text=incorrect, width=len(incorrect), bg='orange')
boxInco.pack()
else:
Textcorrect = ('Correct!')
CorrectMessage = Label(root, text=Textcorrect, width=len(Textcorrect), bg='orange')
CorrectMessage.pack()
# creates a Tkinter window
self.root = Tk()
self.root.title("Math Quiz")
self.root["padx"] = 40
self.root["pady"] = 20
# Creates a text frame to hold the text Label and the Entry widget
textFrame = Frame(self.root)
#Creates a Label in textFrame
entryLabel = Label(textFrame)
entryLabel["text"] = "Answer:"
entryLabel.pack(side=LEFT)
# Creates an Entry Widget in textFrame
entryWidget = Entry(textFrame)
entryWidget["width"] = 50
entryWidget.pack(side=LEFT)
textFrame.pack()
#instructions
directions = ('Click start to begin. You will be asked a series of questions.')
instructions = Label(root, text=directions, width=len(directions), bg='orange')
instructions.pack()
Sub = lambda: Submit(answer, entryWidget)
#stopwatch = lambda: start(answer)
# create needed widgets
label = Label(self.root, text='0.0')
btn_submit = Button(self.root, text="Submit", command = Sub)
btn_start = Button(self.root, text="Start", command = start)
btn_submit.pack()
btn_start.pack()
label.pack()
# start the event loop
self.root.mainloop()
В данный момент он удаляет первое окно, но ничего не делает со вторым, без сообщения об ошибке.нет ничего.