I want the program to switch display window, for example when I click on the button Next (the variable quit_button) I will see the text in label3 or the text in label2 "Hey There! Welcome to TutorialsPoint." or "Find all the interesting Tutorials." When I click on the. button Next nothing is happening. I tried to search for similar questions to mine but I didnt understand what I should add or change
import json
from time import sleep
import pywhatkit
import requests
from os import environ
import threading
from tkinter import Tk, Label, Button, Radiobutton, StringVar, Frame
import requests
from googletrans import Translator
PARAMETERS = {
"amount": 100,
"type": "multiple"
}
FONT=("Courier",30)
radio_buttons_list = []
questions=[{"question":{"what is a logic bomb":["A computer virus","a piece of code intentionally inserted into a software"]},
"answer":"2"}]
alphabet=[]
index = 0
tk = Tk()
greet = Frame(tk)
order = Frame(tk)
# Define a function for switching the frames
def change_to_greet():
greet.pack(fill='both', expand=1)
order.tkraise()
def change_to_order():
order.pack(fill='both', expand=1)
greet.tkraise()
def check_questions(i,answer,record):
'''
:type answer:str
:param i:
:param answer:
:return:
'''
cnt=1
valid=False
if(str(answer).isalpha()):
for i in range(len(alphabet)):
if(alphabet[i]==str(answer).lower()):
valid=True
break
cnt+=1
if((str(answer)==questions[i]["answer"]) or (str(cnt)==questions[i]["answer"] and valid)):
record+=1
def questions_generator()->None:
translator = Translator()
previous_string="{0}".format(questions[0]["question"].keys())
return translator.translate(previous_string[len("dict_keys"):], src="en", dest="he").text
def radio_buttons(self):
"""To create four options (radio buttons)"""
# initialize the list with an empty list of options
choice_list = []
# position of the first option
y_pos = 220
# adding the options to the list
while len(choice_list) < 4:
# setting the radio button properties
radio_btn = Radiobutton(text="", variable="", value='', font=("ariel", 14))
# adding the button to the list
choice_list.append(radio_btn)
# placing the button
radio_btn.place(x=200, y=y_pos)
# incrementing the y-axis position by 40
y_pos += 40
# return the radio buttons
return choice_list
def increment(tk,index,question_data,selected_option):
global radio_buttons_list
global labal
labal.config(text=question_data[index+1]["question"])
answers=question_data[index]["incorrect_answers"]
answers.append(question_data[index]["correct_answer"])
for answer in range(len(radio_buttons_list)):
radio_buttons_list[answer].config(text=answers[answer],
value=answers[answer], font=("ariel", 14))
selected_option=None
def switch():
global index
if index%2!=0:
change_to_greet()
change_to_order()
def show_selected_option():
print("Selected option:", selected_option.get())
def main():
global user_input
global image_label
global output
global tk
tk.title("violetta QR_code_generator")
tk.config(bg="#E8DFCA")
cnt=0
record=0
response = requests.get(url="https://opentdb.com/api.php", params=PARAMETERS)
question_data = response.json()["results"]
global selected_option
selected_option = StringVar()
global index
global labal
while index in range(len(question_data)):
labal = Label(tk, text=question_data[index]["question"], padx=300, pady=20, font=FONT)
labal.pack(pady=15) # pady display on the top of the window
answers=question_data[index]["incorrect_answers"]
answers.append(question_data[index]["correct_answer"])
global radio_buttons_list
for answer in range(len(answers)):
radio_btn = Radiobutton(tk, text=answers[answer], variable=selected_option,
value=answers[answer], font=("ariel", 14))
radio_btn.place(x=200, y=220)
radio_buttons_list.append(radio_btn)
radio_btn.pack()
selected_option=None
image_label = Label(tk, bg="#e6e6e6")
image_label.pack()
output = Label(tk, text="", bg="#F25252")
output.pack(pady=15)
label3 = Label(greet, text="Hey There! Welcome to TutorialsPoint.", foreground="green3")
label3.pack(pady=20)
label2 = Label(order, text="Find all the interesting Tutorials.", foreground="blue")
label2.pack(pady=20)
quit_button = Button(tk, text="Next",
command=switch(),
width=5, bg="red", fg="white", font=("ariel", 16, " bold"))
quit_button.place(x=700, y=300)
tk.mainloop()
if __name__ == '__main__':
main()