[Tutor] First Gui App - Please scrutinize

John Fouhy john at fouhy.net
Mon Feb 6 23:05:40 CET 2006


On 07/02/06, Paul Kraus <pkraus at pelsupply.com> wrote:
> This is my first gui application. It just takes a percentage and then based on
> some options calculates a new price.

Ok.. A few minor comments ---

> class Application( Frame ):
>     """ Price Calc GUI """
>     def __init__( self, master):
>         Frame.__init__( self, master )
>         self.grid()

When I'm programming in Tkinter, the way I generally think is
"Containers (generally frames) create and place their components."  In
particular, this means I would never write a line like "self.grid()".

The reason for this is because, with more complicated layouts, you
will want to use nested frames to package widgets together.  If you
can combine several widgets together to make something nifty, you may
want to use it in several places, or in different progams.  But if
that "megawidget" has a call to grid() itself, that seriously
restricts your ability to reuse it (what if you want to pack() it?).

>         # Calculate Button
>         self.b_calc = Button( self )
>         self.b_calc[ 'text'    ] = 'Calculate'
>         self.b_calc[ 'command' ] = self.calculate
>         self.b_calc.grid(row=10,column=0)

Why not self.b_calc = Button(self, text='Calculate', command=self.calculate)?
And why save it as self.b_calc at all, since you don't use it?

>         self.test = Radiobutton( self, text = 'Cost', variable =
> self.costlistradial, value = 1, command =
> self.setstatus).grid(row=5,column=0,sticky=W)
>         self.test = Radiobutton( self, text = 'List', variable =
> self.costlistradial, value = 0, command =
> self.setstatus).grid(row=6,column=0,sticky=W)

Why are you assigning these to self.test?
(in particular, you realise that the results of these grid() calls
will be None?)

>         if (self.costlistradial.get()):
>             self.e_list['state'] = 'disabled'
>             self.e_cost['state'] = 'normal'

My preference is to use DISABLED and NORMAL (the Tkinter constants),
rather than 'disabled' and 'normal'.  Just in case they ever change...

HTH...

--
John.


More information about the Tutor mailing list