I am writing a program for passing testing in Python, but I can’t think out how to work with the GUI correctly. I have to close the window every time to switch to the next question. How best to cope with the task? Surely I am missing a simple and concise solution for no experience.
from random import shuffle from tkinter import * def count1(event): global ans1, answers, score if ans1 == answers[0]: score += 1 def count2(event): global ans1, answers, score if ans1 == answers[1]: score += 1 def count3(event): global ans1, answers, score if ans1 == answers[0]: score += 1 score = 0 tests = open('input.txt', 'r', encoding='utf-8') for i in range(0, 3): question = tests.readline() ans1 = tests.readline().strip() ans2 = tests.readline().strip() ans3 = tests.readline().strip() answers = [ans1, ans2, ans3] shuffle(answers) print(question) shuffle(answers) print(*answers, sep='\n') root = Tk() lab = Label(root, text=question, font="Arial 18") lab.pack() answ1 = Button(root) answ1['text'] = answers[0] answ1.bind('<Button-1>', count1) answ1.pack() answ2 = Button(root) answ2['text'] = answers[1] answ2.bind('<Button-1>', count2) answ2.pack() answ3 = Button(root) answ3['text'] = answers[2] answ3.bind('<Button-1>', count3) answ3.pack() root.mainloop() print(score)