When the button is clicked, it must create a label for question and buttons for options. And when it’s clicked it must print the answer is correct or incorrect. But it only creates one button and it only prints incorrectly.
def show_question(file_name):
with open(f"resimden_text\soru_liste\{file_name}", "r") as file:
content = file.read()
parts = content.split("nn")
question = parts[0].replace("nnnSoru:n", "")
options = parts[1:]
gizle=ctk.CTkFrame(window, width=1000,height=500)
gizle.place(anchor="n",relx=0.5,rely=0)
question_label = ctk.CTkLabel(gizle, text=question)
question_label.place(relx=0.5, rely=0.01, anchor="n")
y_offset = 0.2
def check_answer(option, correct):
if correct in option:
result = "Answer is correct"
else:
result = "Answer is incorrect"
result_label = ctk.CTkLabel(window, text=result)
result_label.place(relx=0.5, rely=y_offset + len(options) * 0.05 + 0.05, anchor="n")
for i, option in enumerate(options):
option_text = option.split(':',maxsplit=1)[0]
option=option.replace(option_text,"")
is_correct = option.split(r'([A-Z][).])',maxsplit=1)[0].strip()
print("option text",option_text,"is correct",is_correct,"option",option)
option_button = ctk.CTkButton(gizle, text=option_text, command=lambda: check_answer(option_text, is_correct),corner_radius=5, fg_color="#ff5500",text_color="#000", hover_color="#dd3300")
option_button.place(relx=0.5, rely=y_offset + i * 0.05, anchor="n")
This is the part of my code that must do it.
New contributor
Raprer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1