user interface - Python Event binding on label , Event and binding in differents class -
my problem have binding label event , event in different classes dont know how assign label event in class.i try so:
class windowinhalt(): def label(self): label = label(self.tkwindow, text="what fuck", fg="black",bg="lightyellow", font=('arial', 14)) label.bind("<button-1>", eventsbinding.test) #here assign label.place(x=300, y=50, width="200", height="20")
and here event class:
class eventsbinding(windowinhalt): def test(self, event): print("gedrückt")
when start error:
traceback (most recent call last): file "d:\programme\python\lib\tkinter\__init__.py", line 1699, in __call__ return self.func(*args) typeerror: callback() missing 1 required positional argument: 'event'
if can me gratefull ^^
edit 1: here full code
#mein erstes gui python programm mit tkinter #created: july,2017 #creator: yuto tkinter import * #class für den inhalt des windows z.b. label class windowinhalt(): def label(self): label = label(self.tkwindow, text="what fuck", fg="black",bg="lightyellow", font=('arial', 14)) label.bind("<button-1>", eventsbinding.test) label.place(x=300, y=50, width="200", height="20") class eventsbinding(windowinhalt): def test(self, event): print("gedrückt") #class für das window sich hier wird dann auch z.b. inhalt eingebunden class window(windowinhalt): def __init__(self): super().__init__() self.tkwindow = tk() self.label() self.windowsettings() #settings für das window z.b. größe def windowsettings(self): self.tkwindow.configure(background="lightyellow") self.tkwindow.title("gui lalallalala") self.tkwindow.wm_geometry("800x400+600+300") self.tkwindow.mainloop() #only ausführen wenn es nicht eingebunden ist if __name__ == "__main__": print("starten") w = window() else: print("dise datei bitte nicht einbinden!")
in code need create instance of eventsbinding
, , call method on instance
events_binding = eventsbinding(...) ... label.bind("<button-1>", events_binding.test)
if don't want create instance, you'll need define method static method
class eventsbinding(windowinhalt): @staticmethod def test(event): print("gedrückt")
Comments
Post a Comment