I am kind of new to OOP and have been making a few Tkinter applications in Python.
My way to create a GUI is to create only one class with all the graphical part in the constructor function and have instance methods for all the "commands" triggered within the constructor function.
#Example
class GUI:
def __init__(self,master):
# Code for buttons, frames commands etc.
def command1(self):
# Do stuff
Is there a way I can create multiple classes to make the code more readable? I know it will not affect the actual performance of the application and will still work the same way. Although I wanted to learn to write better more readable code and dividing everything into classes. My aim would be to create a base class for the graphical stuff and other (static)classes with various functions for when commands are called.
I tried to do the following using inheritance and had no success:
#Example
root = Tk()
root.geometry("400x350"
class GUI:
def __init__(self,master):
# Code for buttons, frames commands etc.
# When calling a command specific_commands.command1()
class specific_commands(GUI):
def __init__(self,master):
super().__init__(self,master)
def command1 (self):
#Do stuff
GUI(root)
root.mainloop()
What would be your suggestion when trying to do this? Is there another better way I can do this?
Thank you in advance for the help!