[Tutor] Raiobutton question

Glen Wheeler wheelege@tsn.cc
Mon, 12 Feb 2001 19:01:08 +1100


  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.