Tkinter Problem with Radiobuttons

richard_chamberlain at my-deja.com richard_chamberlain at my-deja.com
Wed Jul 19 03:28:26 EDT 2000


Hi Ryan,

You are getting the value of self.selection as if it were a variable
rather than a class. To get the current value of self.selection use
self.selection.get(). An example:

from Tkinter import *
root=Tk()

selection=IntVar()
nativeButton=Radiobutton(root,text="Native: CFD Datasets produced on
this OS",
                         variable=selection,value=0)
bigEButton=Radiobutton(root,text="Big Endian: Solaris,SGI, Motorola",
                       variable=selection, value=1)
littleEButton=Radiobutton(root,text="Little Endian:Intel, DEC",
                          variable=selection,value=2)
def Ok():
    print 'This is selection.get():',selection.get()
    print 'This is just selection:',selection
okButton=Button(root, text="Ok", command=Ok)
nativeButton.pack(anchor=NW,side=TOP)
bigEButton.pack(anchor=NW,side=TOP)
littleEButton.pack(anchor=NW,side=TOP)
okButton.pack(anchor=NE,side=TOP)

root.mainloop()

Notice the two print statements in Ok(), one returns the PY_VAR which
is how IntVar represents it self.

Richard


In article <3974E55A.FED978BD at leland.stanford.edu>,
  Ryan Vartanian <vartan at leland.stanford.edu> wrote:
>
> I am trying to use radiobuttons to select a value for a program, and I
> am haveing trouble with the IntVar() and StringVar() classes.
>
> My code looks like this:
>
> self.selection=IntVar()
> self.nativeButton=Radiobutton(self.byteWindow, text="Native: CFD
> Datasets produced on this OS", variable=self.selection, value=0)
>
> self.bigEButton=Radiobutton(self.byteWindow, text="Big Endian:
Solaris,
> SGI, Motorola", variable=self.selection, value=1)
>
> self.littleEButton=Radiobutton(self.byteWindow, text="Little Endian:
> Intel, DEC", variable=self.selection, value=2)
>
> self.okButton=Button(self.byteWindow, text="Ok", command=self.Ok)
> self.cancelButton=Button(self.byteWindow, text="Cancel",
> command=self.Cancel)
>
> All of this is packed in window, and things when I select a given
> radiobutton, the value of the variable is not 0, 1, or 2, but PY_VAR0,
> PY_VAR1, or PY_VAR2.  The documentation for IntVar() is sparse at
best.
> Any suggestions on what is going on here?
>
> Ryan Vartanian
>


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list