Anonymous
Ошибка TtkBootstrap «bgerror не удалось обработать фоновую ошибку» при уничтожении корневого окна
Сообщение
Anonymous » 26 ноя 2024, 05:56
У меня есть простое приложение, которому нужно открыть окно для входа пользователя в систему (в примере это «root»). После проверки учетных данных окно входа должно закрыться и открыться главное окно (в данном примере — MainWindows).
Проблема в том, что когда я уничтожаю окно входа в систему, и создать основной, всегда возникает следующая ошибка и программа зависает:
Код: Выделить всё
bgerror failed to handle background error.
Original error: can't invoke "event" command: application has been destroyed
Error in bgerror: can't invoke "tk" command: application has been destroyed
Код выглядит следующим образом:
Код: Выделить всё
import tkinter as tk
from tkinter import filedialog
import ttkbootstrap as tb
from ttkbootstrap.dialogs import Messagebox
# login check
def login_check(username, password):
if username == "a" and password == "p":
return True
else:
return False
# login function
def on_login_click():
username = ent_codice_utente.get()
password = ent_password.get()
if login_check(username, password):
root.destroy()
MainWindow()
else:
err_credential = Messagebox.show_error('Invalid credential', parent=root)
def MainWindow():
MainWindow = tb.Window(title='GESCON', themename='superhero')
MainWindow.geometry('1366x768')
MainWindow.columnconfigure(0, weight=1)
MainWindow.rowconfigure(0, weight=1)
MainWindow.rowconfigure(1, weight=4)
frm_filtri = tb.LabelFrame(MainWindow, text="Filter", borderwidth=2)
frm_filtri.columnconfigure(0, weight=10)
frm_filtri.columnconfigure(1, weight=10)
frm_filtri.columnconfigure(2, weight=10)
frm_filtri.rowconfigure(0, weight=10)
frm_filtri.rowconfigure(1, weight=10)
frm_filtri.rowconfigure(2, weight=10)
frm_griglia = tb.LabelFrame(MainWindow, text='Result', borderwidth=2)
frm_filtri.grid(column=0, row=0, sticky=(tk.W, tk.E, tk.N, tk.S), padx=5, pady=5)
frm_griglia.grid(column=0, row=1, sticky=(tk.W, tk.E, tk.N, tk.S), padx=5, pady=5)
btn_elabora = tb.Button(frm_filtri, text='Search')
btn_elabora.grid(column=3, row=2, padx=50, pady=5)
menubar = tb.Menu(MainWindow)
MainWindow.config(menu=menubar)
menu_file = tb.Menu(menubar, tearoff=0)
menu_help = tb.Menu(menubar, tearoff=0)
menubar.add_cascade(label='File', menu=menu_file)
menubar.add_cascade(label='Help', menu=menu_help)
menu_anagrafiche = tb.Menu(menu_file, tearoff=0)
menu_file.add_cascade(label='Anagrafiche', menu=menu_anagrafiche)
menu_file.add_separator()
menu_file.add_command(label='Import file')
menu_file.add_separator()
menu_file.add_command(label='Exit')
menu_help.add_command(label='Info')
#Login window
root = tb.Window(title='Login', themename='superhero')
root.geometry('500x300')
lbl_codice_utente = tb.Label(root, text="User:")
ent_codice_utente = tb.Entry(root)
lbl_password = tb.Label(root, text="Password:")
ent_password = tb.Entry(root, show="*")
btn_login = tb.Button(root, text="Login", bootstyle='success, outline', command=on_login_click)
btn_exit = tb.Button(root, text="Exit", bootstyle='danger, outline', command = lambda:root.destroy())
lbl_codice_utente.grid(padx=10, pady=10, column=0, row=0, sticky='e')
ent_codice_utente.grid(pady=5, column=1, row=0, sticky='w')
lbl_password.grid(padx=10, pady=10, column=0, row=1, sticky='e')
ent_password.grid(pady=5, column=1, row=1, sticky='w')
btn_login.grid(pady=20, column=0, row=3)
btn_exit.grid(pady=20, column=1, row=3)
root.mainloop()
Есть предложения, как устранить ошибку или добиться желаемого поведения другим способом?
Заранее благодарен.
Подробнее здесь:
https://stackoverflow.com/questions/780 ... stroy-root
1732589807
Anonymous
У меня есть простое приложение, которому нужно открыть окно для входа пользователя в систему (в примере это «root»). После проверки учетных данных окно входа должно закрыться и открыться главное окно (в данном примере — MainWindows). Проблема в том, что когда я уничтожаю окно входа в систему, и создать основной, всегда возникает следующая ошибка и программа зависает: [code]bgerror failed to handle background error. Original error: can't invoke "event" command: application has been destroyed Error in bgerror: can't invoke "tk" command: application has been destroyed [/code] Код выглядит следующим образом: [code]import tkinter as tk from tkinter import filedialog import ttkbootstrap as tb from ttkbootstrap.dialogs import Messagebox # login check def login_check(username, password): if username == "a" and password == "p": return True else: return False # login function def on_login_click(): username = ent_codice_utente.get() password = ent_password.get() if login_check(username, password): root.destroy() MainWindow() else: err_credential = Messagebox.show_error('Invalid credential', parent=root) def MainWindow(): MainWindow = tb.Window(title='GESCON', themename='superhero') MainWindow.geometry('1366x768') MainWindow.columnconfigure(0, weight=1) MainWindow.rowconfigure(0, weight=1) MainWindow.rowconfigure(1, weight=4) frm_filtri = tb.LabelFrame(MainWindow, text="Filter", borderwidth=2) frm_filtri.columnconfigure(0, weight=10) frm_filtri.columnconfigure(1, weight=10) frm_filtri.columnconfigure(2, weight=10) frm_filtri.rowconfigure(0, weight=10) frm_filtri.rowconfigure(1, weight=10) frm_filtri.rowconfigure(2, weight=10) frm_griglia = tb.LabelFrame(MainWindow, text='Result', borderwidth=2) frm_filtri.grid(column=0, row=0, sticky=(tk.W, tk.E, tk.N, tk.S), padx=5, pady=5) frm_griglia.grid(column=0, row=1, sticky=(tk.W, tk.E, tk.N, tk.S), padx=5, pady=5) btn_elabora = tb.Button(frm_filtri, text='Search') btn_elabora.grid(column=3, row=2, padx=50, pady=5) menubar = tb.Menu(MainWindow) MainWindow.config(menu=menubar) menu_file = tb.Menu(menubar, tearoff=0) menu_help = tb.Menu(menubar, tearoff=0) menubar.add_cascade(label='File', menu=menu_file) menubar.add_cascade(label='Help', menu=menu_help) menu_anagrafiche = tb.Menu(menu_file, tearoff=0) menu_file.add_cascade(label='Anagrafiche', menu=menu_anagrafiche) menu_file.add_separator() menu_file.add_command(label='Import file') menu_file.add_separator() menu_file.add_command(label='Exit') menu_help.add_command(label='Info') #Login window root = tb.Window(title='Login', themename='superhero') root.geometry('500x300') lbl_codice_utente = tb.Label(root, text="User:") ent_codice_utente = tb.Entry(root) lbl_password = tb.Label(root, text="Password:") ent_password = tb.Entry(root, show="*") btn_login = tb.Button(root, text="Login", bootstyle='success, outline', command=on_login_click) btn_exit = tb.Button(root, text="Exit", bootstyle='danger, outline', command = lambda:root.destroy()) lbl_codice_utente.grid(padx=10, pady=10, column=0, row=0, sticky='e') ent_codice_utente.grid(pady=5, column=1, row=0, sticky='w') lbl_password.grid(padx=10, pady=10, column=0, row=1, sticky='e') ent_password.grid(pady=5, column=1, row=1, sticky='w') btn_login.grid(pady=20, column=0, row=3) btn_exit.grid(pady=20, column=1, row=3) root.mainloop() [/code] Есть предложения, как устранить ошибку или добиться желаемого поведения другим способом? Заранее благодарен. Подробнее здесь: [url]https://stackoverflow.com/questions/78014153/ttkbootstrap-error-bgerror-failed-to-handle-background-error-when-destroy-root[/url]