January 10th, 2013, 12:57 PM
Question about classes.
Since i have to build a python gui program, with many features like: Updating label text from sql database, setting image's as buttons and background.. I was wondering do i need to use classes? I will use tkinter to do such a program, but i have seen many people using classes for their gui programs. My problem is that i don't understand how they work and it's really complicated for me .
So can i make a good flexible program without classes? Why are people using classes when they can make a program without them?
take a look of this code i found online:
What does Class aplication(frame) do? Is it possible to do same, but without class?
def __init__(self, master=None):
self.parent = master
self.outputBox = Text(self.parent, bg='yellow', height= 10, fg='green', relief=SUNKEN, yscrollcommand='TRUE')
self.button1 = Button(self.parent, text='button1', width=20, bg ='blue', fg='green', activebackground='black', activeforeground='green')
self.button1.pack(side=RIGHT, padx=5, pady=5)
self.button2 = Button(self.parent, text='button2', width=25, bg='white', fg='green', activebackground='black', activeforeground='green')
self.button2.pack(side=LEFT, padx=5, pady=5)
Can you please explain me a bit, i am really confused :/.. Is class alternative or only way?
Thanks in advance soo much!
January 10th, 2013, 02:12 PM
Sure, one can write programs functionally the same without classes. Why use a class when I'll make only one instance of the object???
Many programs have more code than merely the GUI. The GUI provides a user interface to the essence of the program. Classes provide name spaces if nothing more. So do modules.
How can MyException possibly work? There's no code! MyException inherits all the functionality (methods and attributes) of ValueError.
[/code] are essential for python code and Makefiles!