[Tutor] Help understanding classes
Bo
crushed26 at gmail.com
Sat Nov 15 01:29:12 CET 2014
Hello everyone, hope all is well. Was just wondering if I could get some
help understanding classes and how they work. What is the point in OOP if I
don¹t understand classes, are classes not the heart and soul of OOP? I have
been trying to learn classes by practicing with Tkinter building GUIs. Below
is my code, which does work. It simply opens a window. I just don¹t
understand why it works? Where would the rest of my code go(after I write it
of course)? Say, I added code to do something in the window; for example, if
I wanted to add buttons and if a button was clicked, execute some linux
commands and display the output in the window? I don¹t understand where that
code would go. I can easily execute linux commands using subprocess, psutil,
os, and even commands, but how does that all work together with classes? I
feel like all the code I have written thus far is very linear and simple,
and if I can grasp classes I can get out of this stagnate slump.
Thank you in advance.
from Tkinter import *
class test(Frame):
def __init__(self, parent):
Frame.__init__(self, parent)
self.parent = parent
self.initUI()
def initUI(self):
self.parent.title(³TestApp")
self.pack(fill=BOTH, expand=1)
def main():
root = Tk()
root.geometry("250x150+300+300")
app = test(root)
root.mainloop()
if __name__ == '__main__':
main()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20141114/374daf79/attachment.html>
More information about the Tutor
mailing list