Не работают функции у класса усовершенствованной кнопки tkinter python
Есть класс с усовершенствованной кнопкой из tkinter, и при создании он конфликтует с обычными кнопками (кнопки хаотично меняют расположения и параметры).
Так же не работают бинды(.bind()), и через один работают обычные команды типа destroy(), place(), lift()
Можете пожалуйста сказать что у меня не так, если таких конфликтов кнопок вообще можно избежать.
class Button2(tk.Button):
def __init__(self,
master=None,
help_pad=[],
hovercolor='#1589ff',**argss):
"""
улучшенный Button из tikner
"""
super().__init__(master,**argss)
self.argss = argss
if type(help_pad) == list:
self.help_pad_text = help_pad[0] if len(help_pad) >=1 else None
self.help_pad_bg = help_pad[1] if len(help_pad) >=2 else '#212221'
else:
self.help_pad_text = help_pad
self.help_pad_bg = '#212221'
self.hovercolor = hovercolor
if self.hovercolor != False:
self.bind("<Enter>", self.focus_in)
self.bind("<Leave>", self.focus_out)
self.time_help_pad = False
def focus_in(self,event=None):
self['bg'] = self.hovercolor
self.time_help_pad = True
if self.help_pad_text != None:
self.after(1000,lambda: self.open_help_pad(event=event))
try:
self.help_pad.destroy()
except:
pass
def focus_out(self,event=None):
try:
self['bg'] = self.argss['bg']
except:
pass
self.time_help_pad = False
try:
self.help_pad.destroy()
self.help_pad_state = False
except:
pass
def test_to_destroy_help_pad(self):
try:
print(self.winfo_id())
if self.help_pad_state == True:
self.after(10,self.test_to_destroy_help_pad)
except:
try:
self.help_pad.destroy()
except:
pass
def open_help_pad(self,event = None):
if self.time_help_pad == True:
self.help_pad_state = True
self.help_pad=Button2(bg=self.help_pad_bg,text=insert_str(self.help_pad_text,50),fg='white',font=("Consolas", 14, "bold"),border=4,state='disabled')
self.help_pad.place(x=event.x +self.winfo_x(),
y=self.winfo_y()+self.winfo_height(),
height=25* ((len(self.help_pad_text)/50) if (len(self.help_pad_text)/50) >=1 else 1)
)
self.bind("<Destroy>", self.focus_out)
try:
FORM.update_idletasks()
if self.help_pad.winfo_x() + self.help_pad.winfo_width() >= FORM.winfo_width():
self.help_pad.place(x=FORM.winfo_width()-self.help_pad.winfo_width())
except:
pass
self.test_to_destroy_help_pad()
q4=Button2(FORM,command=lambda: q3.config(fg='green'),text='Down',help_pad=['Длинное описание'],width=11,height=1,font=("Consolas", 11, "bold"),bg=standart_backgraund,fg='red',activebackground=standart_backgraund,border=1,relief=RAISED)
q4.place(x=297,y=28)
q5=Button2(FORM,command=lambda: q4.place(y=q4.winfo_y()+20),text='Download2',help_pad=['Описание'],width=11,height=1,font=("Consolas", 11, "bold"),bg=standart_backgraund,fg='red',activebackground=standart_backgraund,border=1,relief=RAISED)
q5.place(x=900,y=28)
Источник: Stack Overflow на русском