I'm on Stackoverflow for the first time and I'm from Russia (suddenly it's important). I'm learning Python and creating a small quiz game with a user interface. There are a few problems that I can't solve:
- I want to create a 2-page game. When the user clicks the OK button, the first page disappears and the second one appears, and the program writes the user's answers to the d3 dictionary. How do I write the user's answers to this dictionary?
- I wrote one sentence on the second page for the test. However, when I click OK, the second page is completely empty.
Here is the code:
import PySimpleGUI as sg
d = {
1: "1. Когда мы познакомились?\n 1) 4 июля\n 2) 20 июля\n 3) 12 июля\n 4) 13 июля",
2: "2. Чего я боюсь больше всего в жизни?",
3: "3. Какой цвет я больше всего предпочитаю?\n 1) розовый\n 2) чёрный\n 3) голубой\n 4) зелёный",
4: "4. Моё тотемное животное?",
5: "5. Какая марка автомобилей мне нравится?\n 1) Audi\n 2) Lamborghini\n 3) Tesla\n 4) Nissan",
6: "6. Мой любимый фрукт летом?\n 1) ананас\n 2) слива\n 3) персик\n 4) инжир",
7: "7. Я верующий – в кого я верю?(это учёный-физик)",
} # Вопросы для викторины
d2 = {
1: 3,
2: "Клоунов",
3: 3,
4: "лиса",
5: 3,
6: 3,
7: "Исаак Ньютон - английский физик, математик, механик и астроном, один из создателей классической физики. Автор фундаментального труда «Математические начала натуральной философии», в котором он изложил закон всемирного тяготения и три закона механики, ставшие основой классической механики.",
} # правильные ответы
d3 = {} # Ответы пользователя
font = ("Times New Roman", 14)
sz1 = (30, 3)
sz2 = (110, 3)
sg.set_options(font=font)
sg.theme("DarkAmber")
column1 = [
[sg.Text("Здравствуйте. Сейчас вы пройдёте небольшую викторину.")],
[sg.Text(d[1]), sg.InputText()],
[sg.Text(d[2], size=(sz1)), sg.Multiline(size=(sz2))],
[sg.Text(d[3]), sg.InputText()],
[sg.Text(d[4]), sg.InputText()],
[sg.Text(d[5]), sg.InputText()],
[sg.Text(d[6]), sg.InputText()],
[sg.Text(d[7], size=(sz1)), sg.Multiline(size=(sz2))],
[sg.Button("ОК"), sg.Button("Выйти")],
] # Первая страница
column2 = [
[sg.Text("А теперь сравним твои ответы с теми, что подготовил я:", size=(30, 3))],
[sg.Button("Выйти")],
] # Вторая страница
layout = [
[
sg.Column(
column1,
scrollable=True,
vertical_scroll_only=True,
visible=True,
key="column1",
size=(1366, 768),
)
],
[
sg.Column(
column2,
scrollable=True,
vertical_scroll_only=True,
visible=False,
key="column2",
size=(1366, 768),
)
],
]
window = sg.Window("Приветик", layout, finalize=True)
window.Maximize()
column1, column2 = window["column1"], window["column2"]
while True:
event, values = window.read()
if event in (sg.WIN_CLOSED, "Выйти"):
break
elif event == "ОК":
column2.update(visible=True)
column1.update(visible=False)
window.close()