Создаю приложение для сдачи экзаменов на Python как курсовую работу

Рейтинг: -1Ответов: 1Опубликовано: 05.03.2023

Все плюс минус понятно и работает, но не могу понять который день как сделать так чтобы тест проходил на следующий вопрос без постоянного открытия нового окна. (То есть по нажатию одной кнопки удалять предыдущие вопросы и выводить новые) срок сдачи проекта уже скоро, а я перелопатил все что мог. Код ниже

import tkinter as tk

#Создание окна
win_chose = tk.Tk()
win_chose.config(bg='#292929')
win_chose.title('Программа тестироваия')
win_chose.geometry(f"{1000}x{600}+{(win_chose.winfo_screenwidth()-1000)//2}+ 
{(win_chose.winfo_screenheight()-600)//2}")
win_chose.resizable(False, False)

questions = tk.Label(win_chose,text='Какой тест будешь проходить?', pady=25, 
bg='#292929', fg='white', font=('Arial', 28, 'bold')).pack()

#Изображение кнопок
im_continue = tk.PhotoImage(file=r'C:\Users\Debian\Desktop\ARGUS\Test 
program\Image\Button\Button.png')
im_continue = im_continue.subsample(4, 3)

def Continue():
    if test1_value.get() == 'Yes':
        win_chose.destroy()
        import test1
        test1.window_test1()
    print('test2', test2_value.get())
    print('test3', test3_value.get())

test1_value = tk.StringVar()
test2_value = tk.StringVar()
test3_value = tk.StringVar()

test1_value.set('No')
test2_value.set('No')
test3_value.set('No')

#Выбор теста
test1 = tk.Checkbutton(win_chose, bg='#292929', activebackground='#292929', fg='black', 
offvalue='No',, variable=test1_value)
test1_l = tk.Label(win_chose, text='1 тест', bg='#292929', fg='white', font=('Arial', 18, 'bold'))
test1.place(x=150, y=150)
test1_l.place(x=175, y=144)
test1.bind('<ButtonPress>',lambda event: test3.deselect())
test1.bind('<ButtonPress>',lambda event: test2.deselect(), '+')

test2 = tk.Checkbutton(win_chose, bg='#292929', activebackground='#292929', fg='black', 
offvalue='No',, variable=test2_value)
test2_l = tk.Label(win_chose, text='2 тест', bg='#292929', fg='white', font=('Arial', 18, 'bold'))
test2.place(x=150, y=200)
test2_l.place(x=175, y=194)
test2.bind('<ButtonPress>',lambda event: test1.deselect())
test2.bind('<ButtonPress>',lambda event: test3.deselect(), '+')

test3 = tk.Checkbutton(win_chose, bg='#292929', activebackground='#292929', fg='black', 
 offvalue='No',, variable=test3_value)
 test3_l = tk.Label(win_chose, text='3 тест', bg='#292929', fg='white', font=('Arial', 18, 'bold'))
 test3.place(x=150, y=250)
 test3_l.place(x=175, y=244)
 test3.bind('<ButtonPress>',lambda event: test1.deselect())
 test3.bind('<ButtonPress>',lambda event: test2.deselect(), '+')

btn_close = tk.Button(win_chose, image=im_continue,  highlightthickness=0, bd=0, 
text='Регистрация')
btn_close.configure(bg='#292929', activebackground='#292929') 
btn_close.place(x=50, y=500, width=170, height=60)
btn_close.bind('<Enter>', lambda event: btn_close.place(x=52, y=502))
btn_close.bind('<Leave>', lambda event: btn_close.place(x=50, y=500))

btn_chose = tk.Button(win_chose, image=im_continue,  highlightthickness=0, bd=0, 
text='Регистрация', command=Continue)
btn_chose.configure(bg='#292929', activebackground='#292929')
btn_chose.place(x=800, y=500, width=170, height=60)
btn_chose.bind('<Enter>', lambda event: btn_chose.place(x=802, y=502))
btn_chose.bind('<Leave>', lambda event: btn_chose.place(x=800, y=500))

#r1.place(x=200, y=250)
#r1_l.place(x=225,y=244)
win_chose.mainloop()

Ответы

▲ 0

Попробуйте создавать фрейм, далее виджеты на нем, а при переходе на некст страницу --> дестроить фрейм. Вот пример вашего кода.

import tkinter as tk

# Создание окна
window = tk.Tk()
window.config(bg='#292929')
window.title('Программа тестироваия')
window.geometry(f"1000x600")
window.resizable(False, False)
win_chose = tk.Frame(window, width=1000, height=600, bg='#292929')
win_chose.pack()

questions = tk.Label(win_chose, text='Какой тест будешь проходить?', pady=25,
                     bg='#292929', fg='white', font=('Arial', 28, 'bold')).place(x=100, y=0)

# Изображение кнопок
im_continue = tk.PhotoImage(file='cat_image.png')
im_continue = im_continue.subsample(4, 3)


def Continue():
    if test1_value.get() == 'Yes':
        win_chose.destroy()
    print('test2', test2_value.get())
    print('test3', test3_value.get())


test1_value = tk.StringVar()
test2_value = tk.StringVar()
test3_value = tk.StringVar()

test1_value.set('No')
test2_value.set('No')
test3_value.set('No')

# Выбор теста
test1 = tk.Checkbutton(win_chose, bg='#292929', activebackground='#292929', fg='black',
                       offvalue='No',, variable=test1_value)
test1_l = tk.Label(win_chose, text='1 тест', bg='#292929', fg='white', font=('Arial', 18, 'bold'))
test1.place(x=150, y=150)
test1_l.place(x=175, y=144)
test1.bind('<ButtonPress>', lambda event: test3.deselect())
test1.bind('<ButtonPress>', lambda event: test2.deselect(), '+')

test2 = tk.Checkbutton(win_chose, bg='#292929', activebackground='#292929', fg='black',
                       offvalue='No',, variable=test2_value)
test2_l = tk.Label(win_chose, text='2 тест', bg='#292929', fg='white', font=('Arial', 18, 'bold'))
test2.place(x=150, y=200)
test2_l.place(x=175, y=194)
test2.bind('<ButtonPress>', lambda event: test1.deselect())
test2.bind('<ButtonPress>', lambda event: test3.deselect(), '+')

test3 = tk.Checkbutton(win_chose, bg='#292929', activebackground='#292929', fg='black',
                       offvalue='No',, variable=test3_value)
test3_l = tk.Label(win_chose, text='3 тест', bg='#292929', fg='white', font=('Arial', 18, 'bold'))
test3.place(x=150, y=250)
test3_l.place(x=175, y=244)
test3.bind('<ButtonPress>', lambda event: test1.deselect())
test3.bind('<ButtonPress>', lambda event: test2.deselect(), '+')

btn_close = tk.Button(win_chose, image=im_continue, highlightthickness=0, bd=0,
                      text='Регистрация')
btn_close.configure(bg='#292929', activebackground='#292929')
btn_close.place(x=50, y=500, width=170, height=60)
btn_close.bind('<Enter>', lambda event: btn_close.place(x=52, y=502))
btn_close.bind('<Leave>', lambda event: btn_close.place(x=50, y=500))

btn_chose = tk.Button(win_chose, image=im_continue, highlightthickness=0, bd=0,
                      text='Регистрация', command=Continue)
btn_chose.configure(bg='#292929', activebackground='#292929')
btn_chose.place(x=800, y=500, width=170, height=60)
btn_chose.bind('<Enter>', lambda event: btn_chose.place(x=802, y=502))
btn_chose.bind('<Leave>', lambda event: btn_chose.place(x=800, y=500))

# r1.place(x=200, y=250)
# r1_l.place(x=225,y=244)
window.mainloop()