import tkinter as tk
from tkinter import StringVar
root = tk.Tk()
root.geometry('500x350')

questions= ["What is the longest river in the world? ",
"What is the capital of Japan? ",
"What is the tallest mountain in the world? " ]

options = [("Amazon River", "Congo River", "Mississippi River", "The Nile River", "The Nile River"),
("Tokyo", "Beijing", "Rome","Ankara", "Tokyo"),
("Mount Fuji","Cho Oyu","Lhotse","Mount Vincent", "Mount Vincent")]

frame = tk.Frame(root,padx=10, pady=10, bg='white')
question_label = tk.Label(frame, height=5, width=36,bg="pink", fg='black', font=("verdana", 20),wraplength=500)

v1 = StringVar(frame)
v2 = StringVar(frame)
v3 = StringVar(frame)
v4 = StringVar(frame)

option1 = tk.Radiobutton(frame, fg= 'black', bg="#fff", variable=v1, font=("verdana",20),command = lambda : checkAnswer(option1))
option2 = tk.Radiobutton(frame, fg= 'black', bg="#fff", variable=v2, font=("verdana",20), command = lambda : checkAnswer(option2))
option3 = tk.Radiobutton(frame, fg= 'black', bg="#fff", variable=v3, font=("verdana",20),command = lambda : checkAnswer(option3))
option4 = tk.Radiobutton(frame, fg= 'black', bg="#fff", variable=v4, font=("verdana",20),command = lambda : checkAnswer(option4))

button_next = tk.Button(frame, text="Next", bg= 'blue', font=("verdana",20), 
                        command = lambda: desplayNextQuestion())

frame.pack(fill="both", expand="true")
question_label.grid(row=0, column=0)

option1.grid(sticky= "w", row=1, column=0)
option2.grid(sticky= "w", row=2, column=0)
option3.grid(sticky= "w", row=3, column=0)
option4.grid(sticky= "w", row=4, column=0)

button_next.grid(row=6, column=0)

index = 0
correct = 0

#لعرض الخيارات
def disableButtons(state):
    option1['state'] = state 
    option2['state'] = state
    option3['state'] = state
    option4['state'] = state

#للاجابه المختاره
def checkAnswer(radio):
    global correct, index
        #الاختيار الرابع صح 
    if radio['text'] == options[index][4]:
        correct += 1
    index += 1
    disableButtons("disable")

#next question
def desplayNextQuestion():

    global index, correct

    if button_next['text'] == 'Restart The Quiz' :
        correct = 0
        index = 0
        question_label['bg'] = 'pink'
        button_next["text"] = 'Next'
    
    if index == len (options):
        question_label["text"] = str(correct) + "/" + str(len(options))
        button_next['text'] = 'Restart The Quiz'
        if correct >= len (options)/2:
            question_label['bg'] = 'green'
        else:
            question_label['bg'] = 'red'

    else:
        question_label["text"] = questions[index]



    disableButtons('normal')
    opts = options[index]
    option1['text'] = opts[0]
    option2['text'] = opts[1]
    option3['text'] = opts[2]
    option4['text'] = opts[3]
    v1.set(opts[0])
    v2.set(opts[1])
    v3.set(opts[2])
    v4.set(opts[3])


    if index == len(options) - 1:
        button_next ["text"] = 'cleck the result'
    
desplayNextQuestion()


root.mainloop()


