I want to make my quiz game as a gui, I made it without one. I tried looking all over the internet. I've been trying to find a way to make it work in tkinter but its so confusing. Also I am really motivated about finding a solution but its been 3 days already and I couldn't find one.
I will try to explain more, so basically I couldn't make my quiz game work using tkinter, I tried to make a loop so I don't have to make labels over and over again, It will take so much time and its not that efficient. Would you please help me out.
This is my code without the gui
class Question:
def __init__(self,prompt,answer, answer2):
self.answer = answer
self.prompt = prompt
self.answer2 = answer2
question_prompts = [
"When did Tunisia gain independence? \n 1956 , 1984 , 1965 \n", "What is the captial of tunis ? \n Tunis, Gafsa, Nabuel \n",
"Who won 2018 football world cup ? \n Italy, France, England \n","how long is the eiffel tower ?\n 324m, 354m, 412m \n",
"What is the heaviest metal \n Iron, Copper, Uraniam \n "
]
questions = [
Question(question_prompts[0], "1956","1956"),
Question(question_prompts[1], "Tunis","tunis"),
Question(question_prompts[2], "France","france"),
Question(question_prompts[3], "324m","324"),
Question(question_prompts[4], "Uraniam","uraniam")
]
def playgame():
score = 0
for question in questions:
answer = input(question.prompt)
if answer == question.answer:
score += 1
elif answer == question.answer2:
score += 1
print("You have answerd " + str(score) + " / " + str(len(questions)) + " Correct answers ")
playgame()
This is my quiz with gui but its buggy
import tkinter as tk
from time import sleep
win = tk.Tk()
win.title("Learning game")
class Question:
def __init__(self,prompt,answer, answer2):
self.answer = answer
self.prompt = prompt
self.answer2 = answer2
question_prompts = [
"When did Tunisia gain independence? \n 1956 , 1984 , 1965 \n", "What is the captial of tunis ? \n Tunis, Gafsa, Nabuel \n",
"Who won 2018 football world cup ? \n Italy, France, England \n","how long is the eiffel tower ?\n 324m, 354m, 412m \n",
"What is the heaviest metal \n Iron, Copper, Uraniam \n "
]
questions = [
Question(question_prompts[0], "1956","1956"),
Question(question_prompts[1], "Tunis","tunis"),
Question(question_prompts[2], "France","france"),
Question(question_prompts[3], "324m","324"),
Question(question_prompts[4], "Uraniam","uraniam")
]
s = tk.StringVar()
useranwser = tk.StringVar()
def ask():
for questionpop in questions:
s.set(question_prompts.pop(0))
for question in questions:
q = tk.Label(win)
q.grid(row = 0, column = 0)
q.config(textvariable = s)
u_answer = tk.Entry(win, textvariable = useranwser)
u_answer.grid(row = 1, column = 0)
b = tk.Button(win, text ="Submit", command = ask)
b.grid(row = 2, column =0 )
score = 0
if useranwser == question.answer:
print("Correct")
score += 1
else:
print("Uncorrect")
ask()
win.mainloop()
ask()