I have a file that contains a class definition. This class definition stores Tkinter Button
objects, and when these buttons are pressed, I need them to run a function in main.py. My file structure is as follows:
- main.py
- Classes (Folder)
- class.py
- another_class.py
class.py
contains a class with a method render
, which creates and shows the button, saving it to an attribute button
:
def Render(self):
self.__scrnPos = self.GetScrnPos()
if self.tile == None:
txt = self.multiplier
else:
txt = self.tile.GetLetter() + str(self.tile.GetValue())
self.colour = self.__GetColour()
button = tk.Button(
text = txt,
font = self.font,
command = lambda: test(),
bg = self.colour).place(
x = self.__scrnPos[0],
y = self.__scrnPos[1],
width = self.__size,
height = self.__size)
return button
When the button is pressed, it should run the subroutine test
in main.py
.