Имея тот же _tkinter.TclError без решенияPython

Программы на Python
Anonymous
Имея тот же _tkinter.TclError без решения

Сообщение Anonymous »

Код: Выделить всё

class AutoCompleteEntry(CTkEntry):
def __init__(self, master, suggestions, placeholder=None, **kwargs):
self.var = tk.StringVar()
super().__init__(master, textvariable=self.var, **kwargs)
self.suggestions = suggestions
self.placeholder = placeholder

if self.placeholder:
self.insert_placeholder()

self.var.trace_add('write', self.changed)
self.bind("", self.selection)
self.bind("", self.move_up)
self.bind("", self.move_down)
self.bind("", self.on_focus_in)
self.bind("", self.on_focus_out)

self.lb_up = False
self.lb_frame = None
self.lb = None
self.listbox_destroyed = False

def insert_placeholder(self):
self.insert(0, self.placeholder)
self.configure(fg_color="#242424")

def remove_placeholder(self):
current_text = self.get()
if current_text == self.placeholder:
self.delete(0, tk.END)
self.configure(fg_color="#242424")

def on_focus_in(self, event):
if self.get() == self.placeholder:
self.delete(0, tk.END)
self.configure(fg_color="#242424")

def on_focus_out(self, event):
if not self.get():
self.insert_placeholder()

def changed(self, *args):
if self.var.get() == '' or self.listbox_destroyed:
if self.lb_up:
self.destroy_listbox()
else:
words = self.comparison()
if words:
if not self.lb_up:
self.lb_frame = CTkFrame(self.master)
self.lb = ctl.CTkListbox(self.lb_frame,
width=400,
border_width=0,
fg_color="#242424",
font=("Satoshi-Regular", 20),
text_color="#F3F3F3",
bg_color="#111111",
hover_color="#373737",
command=self.show_value)
self.lb.bind("", self.selection)
self.lb.bind("", self.selection)
self.lb.bind("", self.selection)
self.lb.pack(side="top", fill="both", expand=True)
self.lb_frame.place(x=self.winfo_x(), y=self.winfo_y() + self.winfo_height())
self.lb_up = True
if self.lb and self.lb.winfo_exists():
self.lb.delete(0, tk.END)
for w in words:
self.lb.insert(tk.END, w)
else:
self.destroy_listbox()

def destroy_listbox(self):
if self.lb_up:
if self.lb and self.lb.winfo_exists():
self.lb.destroy()
self.lb = None  # Set to None after destruction
if self.lb_frame and self.lb_frame.winfo_exists():
self.lb_frame.destroy()
self.lb_frame = None  # Set to None after destruction
self.lb_up = False
self.listbox_destroyed = True

def selection(self, event):
if self.lb_up and self.lb and self.lb.winfo_exists():
try:
self.var.set(self.lb.get(tk.ACTIVE))
except tk.TclError:
return
self.destroy_listbox()
self.icursor(tk.END)

def move_up(self, event):
if self.lb_up and self.lb and self.lb.winfo_exists():
try:
if self.lb.curselection() == ():
index = '0'
else:
index = self.lb.curselection()[0]
if index != '0':
self.lb.selection_clear(first=index)
index = str(int(index) - 1)
self.lb.selection_set(first=index)
self.lb.activate(index)
except tk.TclError:
return

def move_down(self,  event):
if self.lb_up and self.lb and self.lb.winfo_exists():
try:
if self.lb.curselection() == ():
index = '-1'
else:
index = self.lb.curselection()[0]
if index != tk.END:
self.lb.selection_clear(first=index)
index = str(int(index) + 1)
self.lb.selection_set(first=index)
self.lb.activate(index)
except tk.TclError:
return

def comparison(self):
if self.listbox_destroyed:
return []
pattern = self.var.get()
return [w for w in self.suggestions if w.lower().startswith(pattern.lower())]

def show_value(self, selected_option):
movie_update(selected_option)

def destroy_widget(self):
self.destroy_listbox()
self.destroy()

global movie_update
def movie_update(name):
movie = name
search.destroy_widget()  # This should safely destroy the widget
video1.release()
video2.release()
landingcanvas.destroy()
Я пытался создать панель поиска с автозаполнением, которая уничтожается при выборе опции из списка.
Этот код выдает следующую ошибку: Исключение в обратном вызове Tkinter
_tkinter.TclError: неверное имя пути к окну ".!ctkcanvas.!ctkframe2.!ctkframe.!canvas.!ctklistbox"
Я не могу найти причину этого, все остальное выполняет предназначенную работу...< /п>

Подробнее здесь: https://stackoverflow.com/questions/787 ... o-solution

Вернуться в «Python»