Values and variables for Tk radio buttons

richard_chamberlain richard_chamberlain at ntlworld.com
Fri Jul 28 13:13:49 EDT 2000


Hi Mark,

Briefly (I'm just on my way out of the door) you should use IntVar instead.

To get the contents of StringVar or IntVar by the way would be
IntVar.get() - so in your case that would be servar.get() (or for that
matter servar.set(A number) )

Richard

Daley, Mark W <mark.w.daley at intel.com> wrote in message
news:75F7304BB41CD411B06600A0C98414FCB36827 at ORSMSX54...
> I am trying to struggle through the design of a GUI using Tkinter.  I'm
not
> doing to bad, for a beginner, but I am having a problem retrieving the
> values assigned by selecting a certain button.  Here is the code I wrote
> (forgive the crudity, I'm not savvy with classes yet!):
>
> from Tkinter import *
> import dbi, odbc
> import time, os, sys
>
> servername = ['Server1', 'Server2', 'Server3']
> name = (('None', 'None'), ('name1', 'Name1'), ('name2', 'Name2'),
('name3',
> 'Name3'))
>
> def die():
> sys.exit()
>
>
> root = Tk()
> root.title("Test GUI")
> servar = StringVar()
> namevar = StringVar()
>
>
> for item in range(len(servername)):
> b1 = Radiobutton(root, text = servername[item], variable = servar,
> value = servername[item])
> b1.grid(row = item, column = 0, sticky=W)
>
>
> for index in range(len(name)):
> b2 = Radiobutton(root, text = name[index][1], variable = namevar,
> value = name[index][1])
> b2.grid(row = index, column = 1, sticky=W)
>
>
> q = Button(root, text = 'Quit', command = die, width = 10)
> q.grid(row = 13, column = 0, sticky = W)
>
>
> root.mainloop()
>
>
> This gives me two columns of radio buttons (the name tuple is longer, and
> contrived since I usually get the values from a database).  I have no idea
> how to get the values from the buttons.  Should I be doing something other
> than StringVar() for servar and namevar?
>
> - Mark
> ----------------------------------------------
> The opinions expressed are mine, and are not necessarily those of my
> employer.
>
>
>





More information about the Python-list mailing list