- Joined
- Mar 23, 2019
- Posts
- 1,515
- Solutions
- 10
- Reaction
- 2,164
- Points
- 663
- Age
- 20
Baka pwede po pahelp sa score nalang po kulang kapag tapos na mag sagot yung user dapat po lalabas yung score eh
Code:
from tkinter import *
from tkinter import messagebox
import random
window = Tk()
window.title("Quiz Game")
window.geometry("800x400")
window.configure(background="Light Gray")
def quit_game():
user_screen.place_forget()
root.pack()
def start_game():
user_screen.place_forget()
root.pack()
score = 0
def next_question():
questions = [
{
"question": "Who found Diariong Tagalog?",
"options": ["A. Juan Luna", "B. Marcelo del Pilar", "C. Pedro Laktaw", "D. Gregorio Sanciano"],
"answer": "B. Marcelo del Pilar"
},
{
"question": "The Political section of the Association Hispano-Filipino was under the charge of:",
"options": ["A. Jose Rizal", "B. Marcelo del Pilar", "C. Dominador Gomez", "D. Tomas Arejola"],
"answer": "B. Marcelo del Pilar"
},
{
"question": "Based on the plan proposed by whom was The Malolos Constitution drafted?",
"options": ["A. Paterno", "B. Calderon", "C. Mabini"],
"answer": "B. Calderon"
},
{
"question": "Taga-Ilog was the pen name which was associated with:",
"options": ["A. Juan Luna", "B. Mariano Ponce", "C. Jose Ma. Panganiban", "D. Antonio Luna"],
"answer": "D. Antonio Luna"
},
{
"question": "Tell the name of the president of the Association La Solidaridad.",
"options": ["A. Galiciano Apacible", "B. Mariano Ponce", "C. Jose Ma. Panganiban",
"D. Manuel Sta. Maria"],
"answer": "A. Galiciano Apacible"
},
{
"question": "Who was the founder of the KKK?",
"options": ["A. Emilio Aguinaldo", "B. Jose Rizal", "C. Andres Bonifacio", "D. Confederate Army"],
"answer": "C. Andres Bonifacio"
},
{
"question": "Considered as the first Philippine hero.?",
"options": ["A. King Philip II of Spain", "B. Lapu-lapu", "C. Jose Rizal", "D. Ferdinand Magellan"],
"answer": "B. Lapu-lapu"
},
{
"question": "Where was the Rizal's novel 'Noli Me Tangere' published?",
"options": ["A. Paris", "B. Manila", "C. Berlin", "D. Tokyo"],
"answer": "C. Berlin"
},
{
"question": "What is considered the earliest form of writing in the Philippines?",
"options": ["A. Kuhitan", "B. Buhid", "C. Baybayin", "D. Tagbanua"],
"answer": "C. Baybayin"
},
{
"question": "Who created the designs for the Philippine national flag?",
"options": ["A. Emilio Aguinaldo", "B. Marcella Agoncillo", "C. Gabriella Silang", "D. Tandang Sora"],
"answer": "A. Emilio Aguinaldo"
}
]
question = random.choice(questions)
global q
global options
q = question["question"]
options = question["options"]
global correct_answer
correct_answer = question["answer"]
q_label.config(text=q)
option_1.config(text=options[0])
option_2.config(text=options[1])
option_3.config(text=options[2])
option_4.config(text=options[3])
def check_answer(answer):
global score
if (answer == correct_answer):
score += 1
messagebox.showinfo("Correct Answer", "Correct! Nicely Done")
else:
messagebox.showerror("Wrong Answer", "Incorrect! Better luck next time!")
next_question()
q_label = Label(window, text="", font=("Helvetica", 16), bg='#FFF5EE')
q_label.pack()
option_1 = Button(window, text="", font=("Helvetica", 14), bg='#EEE5DE', width=20,
command=lambda: check_answer(options[0]))
option_1.pack()
option_2 = Button(window, text="", font=("Helvetica", 14), bg='#EEE5DE', width=20,
command=lambda: check_answer(options[1]))
option_2.pack()
option_3 = Button(window, text="", font=("Helvetica", 14), bg='#EEE5DE', width=20,
command=lambda: check_answer(options[2]))
option_3.pack()
option_4 = Button(window, text="", font=("Helvetica", 14), bg='#EEE5DE', width=20,
command=lambda: check_answer(options[3]))
option_4.pack()
next_question()
user_screen = Frame(bg="Light Gray")
user_screen.place(relx=0.5, rely=0.5, anchor=CENTER)
intro_message = Label(user_screen, width=60, font=("Arial", 20), fg='Black', bg='Yellow', bd=5, text=">>WIZARD GAME<<")
intro_message.pack()
label = Label(user_screen, text="", bg="Light Gray", fg="Light Gray", padx=50, pady=50).pack()
play_b = Button(user_screen, font=("Arial", 13, "bold"), text="Play Game", command=start_game)
play_b.pack()
ins = Button(user_screen, font=("Arial", 13, "bold"), text="Quit Game", command=exit)
ins.pack()
root = Frame(window, bg='cadet blue')
root.pack_forget()
window.mainloop()
Last edited: