almost verbatum ( changed to tkinker rather than Tkinter as I'm using python 3.1.1 )
import tkinter
class App :
def __init__(self) :
self.root = tkinter.Tk()
self.frame = tkinter.Frame(self.root, width=200, height=100)
self.frame.bind("<Button-1>", self.click)
self.frame.pack()
self.root.mainloop()
def click(self, event) :
print("Clicked at :", event.x, event.y)
App()
Same thing can be done non-00 :
import tkinter
root = tkinter.Tk()
frame = tkinter.Frame(root, width = 200, height = 100)
def click(event) :
print("Clicked at :", event.x, event.y)
frame.bind("<Button-1>", click)
frame.pack()
root.mainloop()
Above is only 8 lines and a lot less words compared to the OOP 11 lines.
Yet many tkinter examples I find in docs, courses, books are object-oriented; even the
whole routine as in example one.
I thought the purpose of OOP was to package and reuse the code by instantiating a number
of instances. Why OO code a routine that is used once ? This passeth all understanding.
Can anyone explain ?
Someone on the web gave the quote about OOP : " All I wanted was a banana, and I got
a gorilla holding the banana and the entire jungle".
Thanks for any help. Dave, lost in a jungle in Texas
Edited by Dogstopper:
This post has been edited by Dogstopper: 02 December 2010 - 01:47 PM

New Topic/Question
Reply




MultiQuote




|