My Problem is that i have the binding from the label to his event and the event in different classes but i dont know really how to assign to the label the event in the class.I try it so:
class WindowInhalt():
def label(self):
label = Label(self.tkWindow, text="What the fuck", fg="black",bg="lightyellow", font=('Arial', 14))
label.bind("<Button-1>", EventsBinding.Test) #here is the assign
label.place(x=300, y=50, width="200", height="20")
And here is the event class:
class EventsBinding(WindowInhalt):
def Test(self, event):
print("gedrückt")
When i start it so i get this 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 anybody can help me i am gratefull ^^
EDIT 1: Here is the full code
#Mein Erstes Gui Python Programm mit Tkinter
#Created: July,2017
#Creator: Yuto
from tkinter import *
#class für den Inhalt des Windows z.b. label
class WindowInhalt():
def label(self):
label = Label(self.tkWindow, text="What the 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 an 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!")