ошибка tkinter проверка вне функции

делаю прогу, для открытия файла посредством "ввода пароля" в нестандартном режиме. сначала код выглядел так:

from tkinter import *
import os

#window_settings
root = Tk()
root.title('test')
root.geometry('300x321+800+350')
root.resizable(height=False, width=False)
root.wm_attributes('-alpha', 1.0)
root.configure(background='black')

#values
btn_first = 0
btn_second = 0
btn_third = 0
btn_fourth = 0

#def's
def clicked():
    root.destroy()
    os.startfile('hello.png')


def first():
    global btn_first
    btn_first = btn_first + 1
    if btn_first == 1 and btn_second == 9 and btn_third == 8 and btn_fourth == 7:
        clicked()
def second():
    global btn_second
    btn_second = btn_second + 1
    if btn_first == 1 and btn_second == 9 and btn_third == 8 and btn_fourth == 7:
        clicked()
def third():
    global btn_third
    btn_third = btn_third + 1
    if btn_first == 1 and btn_second == 9 and btn_third == 8 and btn_fourth == 7:
        clicked()
def fourth():
    global btn_fourth
    btn_fourth = btn_fourth + 1
    if btn_first == 1 and btn_second == 9 and btn_third == 8 and btn_fourth == 7:
        clicked()

#buttons
button_first = Button(text='', command=first, activebackground='white', height=10, width=20, background='blue')
button_second = Button(text='', command=second, activebackground='white', height=10, width=20, background='green')
button_third = Button(text='', command=third, activebackground='white', height=10, width=20, background='yellow')
button_fourth = Button(text='', command=fourth, activebackground='white', height=10, width=20, background='red')
button_first.place(x=0, y=0)
button_second.place(x=151, y=0)
button_third.place(x=0, y=161)
button_fourth.place(x=151, y=161)

root.mainloop()

потом я его изменил, (убрал проверку в каждой функции, поставил её в конец) и теперь выглядит так:

from tkinter import *
import os

#window_settings
root = Tk()
root.title('test')
root.geometry('300x321+800+350')
root.resizable(height=False, width=False)
root.wm_attributes('-alpha', 1.0)
root.configure(background='black')

#values
btn_first = 0
btn_second = 0
btn_third = 0
btn_fourth = 0

#def's
def clicked():
    root.destroy()
    os.startfile('hello.png')


def first():
    global btn_first
    btn_first = btn_first + 1

def second():
    global btn_second
    btn_second = btn_second + 1

def third():
    global btn_third
    btn_third = btn_third + 1

def fourth():
    global btn_fourth
    btn_fourth = btn_fourth + 1

if btn_first == 1 and btn_second == 9 and btn_third == 8 and btn_fourth == 7:
    clicked()

#buttons
button_first = Button(text='', command=first, activebackground='white', height=10, width=20, background='blue')
button_second = Button(text='', command=second, activebackground='white', height=10, width=20, background='green')
button_third = Button(text='', command=third, activebackground='white', height=10, width=20, background='yellow')
button_fourth = Button(text='', command=fourth, activebackground='white', height=10, width=20, background='red')
button_first.place(x=0, y=0)
button_second.place(x=151, y=0)
button_third.place(x=0, y=161)
button_fourth.place(x=151, y=161)

root.mainloop()

но так, он не работает, в оригинале при нажатии кнопок в определённом количестве нечего не происходит, приходится менять параметры цифр в коде(переменные btn должны меняться в функциях посредством нажатия кнопки) всё работает, но не так, как задумывалось. да и ещё выходит ошибка:

can't invoke "event" command: application has been destroyed
    while executing
"event generate $w <<ThemeChanged>>"
    (procedure "ttk::ThemeChanged" line 6)
    invoked from within
"ttk::ThemeChanged"

что я делаю не так?


Ответы (0 шт):