[Tutor] Raiobutton question

Glen Wheeler wheelege@tsn.cc
Mon, 12 Feb 2001 21:59:52 +1100


  Thanks, it seems I need more reading on the different methods of the
variable classes.  Python docs, here I come!  The default setting doesn't
really matter...not yet anyway :)

  Glen.

----- Original Message -----
From: Harry Kattz <gibbs05@flash.net>
To: Glen Wheeler <wheelege@tsn.cc>
Cc: <tutor@python.org>
Sent: Monday, February 12, 2001 9:59 PM
Subject: Re: [Tutor] Raiobutton question


> Greetings Glen & All,
>
> Since I'm awake and struggling to learn Tkinter also, I've decided to jump
> in.
>
> I tried your code in PythonWin and the value of x is indeed being set by
the
> radiobutton.
>
> The values stored in the TK variables can be retrieved using their 'get'
> method, so the following modification to the die function should fix your
> output.
>
> def die(x)
>     print 'dead'
>     print x.get()
>
> I think you can find this in the top paragraph on page 152 of 'Python and
> Tkinter Programming' by Grayson.
>
> Your code set the radiobutton's default just fine when I tried it, so I
> can't help you with that one. ;-)
>
> Good luck
> Harry
>
> >   Thanks alot for the help - I understand why that wasn't working.
Also,
> > the reason I had the root = Tk() in there is because Grayson explains he
> > expects that (among other header stuff) at the beginning of all his
> examples
> > (note he says beginning, and not 3rd in line, like I had it).
> >   However, my real problem is still rearing it's ugly head.  Almost the
> same
> > code as before :
> >
> > from Tkinter import *
> >
> > root = Tk()
> >
> > x = IntVar()
> >
> > def die(x):
> >     print 'dead'
> >     print x
> >
> > for text, value in [('Pathetic', 100), ('Good', 60), ('Fun', 40),
> ('Stupid',
> > 15)]:
> >     Radiobutton(root, text=text, value=value, variable=x).pack(anchor=W)
> > b = Button(root, text='lets go', command=
> >            lambda x=x:die(x)).pack()
> >
> > x.set(60)  ## meant to select a radio button as default however does not
> > work
> >
> > mainloop()
> >
> >   Except this one makes a button that is meant to print 'dead' and also
> the
> > value of x.  This doesn't happen, instead it prints the name given to x
> upon
> > its creation.  It appears that x is not changed by the radio buttons, or
> > maybe it isn't even recognised (wrong namespace?  nah cos then the
> > radiobuttons would throw an exception....right?).
> >   I know this is an easy problem - they are the ones I have the most
> trouble
> > with.  It seems I can always work my way through the big ugly hard
> > things...just not the easy ones.
> >
> >   Thanks again,
> >   Glen.
> >
> >
> > _______________________________________________
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor
>