Newbie Tkinter questions

Doru-Catalin Togea doru-cat at ifi.uio.no
Fri Jun 27 06:02:47 EDT 2003


Hei!

I am trying to get up and working with Tkinter fast. I have some
documentation like Fredrik Lundh's An Introduction to Tkinter.

Can you please tell what I am missing in the following programme:

from Tkinter import *

########################################################################
# GLOBAL VARIABLES
########################################################################

root = Tk()
schools = [("HIO", "1"), ("NITH", "2"),]
rbSchools = None 		# initialize later on to a Radiobutton
				# object
lArchiveNo = None		# Label
eArchiveNo = None		# Entry
v = StringVar()
v.set("0") 			# For the Radiobutton: no choice

########################################################################
# FUNCTIONS
########################################################################

def chooseSchool(value):
	print "you have chosen Radiobutton no.", value

########################################################################
# MAIN PROGRAMME
########################################################################

lArchiveNo = Label(root, text = "Sak nr.: ")
lArchiveNo.grid(row = 0, column = 0)
lArchiveNo.pack(side=LEFT)

eArchiveNo = Entry(root, width = 20)
eArchiveNo.grid(row = 0, column = 1)
eArchiveNo.pack(side=LEFT)

# make the radio button for schools:
rbSchools = Radiobutton(root, name = "rbSchools")
	#rbSchools.bind("<Button-1>", chooseSchool)
	#print str(rbSchools)
for text, value in schools:
	rbSchools = Radiobutton(root, text=text, variable=v, \
		value=value, command=chooseSchool(value))
	rbSchools.grid(row = 1, column = 0)
	rbSchools.pack(anchor=W)

root.mainloop()

1) Is the grid used with the Label and the Entry the same as the grid in
the for-loop? (it doesn't seem so, I want the Entry after the Label in the
1st row and the Radiobutton in the 2nd row, first cell or columnspan = 2).

2) How do I capture the change on the Radiobutton? As it is now, the
programme calls chooseSchool with the right value at creation time, not
when I click the Radiobutton. (Or maybe it is called when I click the
Radiobutton as well, but the event is captured and ignored before it
reaches the Radiobutton???)

Thanks if you can help. Is there any documentation which is more detailed
than Lundh's introduction?

Catalin

-- 

	<<<< ================================== >>>>
	<<     We are what we repeatedly do.      >>
	<<  Excellence, therefore, is not an act  >>
	<<             but a habit.               >>
	<<<< ================================== >>>>





More information about the Python-list mailing list