User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Python section within the Software Development category of DaniWeb, a massive community of 402,400 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,912 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Python advertiser: Programming Forums

Python GUI Problem

Join Date: Jul 2006
Posts: 562
Reputation: jrcagle is on a distinguished road 
Rep Power: 4
Solved Threads: 72
jrcagle jrcagle is offline Offline
Posting Pro

Re: Python GUI Problem

  #15  
Sep 7th, 2007
No, it's perfectly fine to insist on complete clarity. That's what good coding is all about.

The disable function needs to be a part of the class because you want it to be something that only DisablerButtons can do. AND, you want each DisablerButton to have its own copy of disable(), so that it can disable its own target.

If you made disable() a public function, outside the class scope, then there would be no easy way to tell disable which target to disable.

But since each DisablerButton has its own copy of the disable() method, the problem is solved: disable operates on self.target.

The reason for the syntax

self.disable

instead of

disable(self)

is that a method is always written in terms of its parent. Try this:

'hi there'.reverse()

Semantically, Python turns 'self.method(arg1, arg2)'

into 'method(self,arg1,arg2)'. But the distinction is made syntactically between the parent (self) and the other arguments so that humans can read it more clearly.

The Button.__init__() line is needed because DisablerButton inherits its properties and methods from Button. Normally, there's a lot that happens behind the scenes when a Button widget is created. All of this occurs in the __init__ method of Button. So DisablerButton calls Button.__init__ to make sure that all of those things happen, like construction of the widget, attachment to mainw, things like that that you don't want to worry about.

Bottom line: it's usually a good idea for children to call the parent's __init__ method.

Hope it helps, and I'll think about the radiobutton problem later.

Jeff
Reply With Quote  
All times are GMT -4. The time now is 1:33 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC