Values and variables for Tk radio buttons
Daley, Mark W
mark.w.daley at intel.com
Fri Jul 28 11:53:13 EDT 2000
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