How to use grid_location (Tkinter)

Carles Sadurní Anguita isard at localhost.localdomain
Thu Aug 24 10:17:40 EDT 2000


Hello,

I would like to divide a window in a 3x3 grid of labels and then know in
which cell did the user click (for instance (2,1)).

I've read Fredrik Lundh's Tkinter Introduction, Tk man pages, chapter 5 from
John Grayson's book, some exemples and so, but I can't figure out how to use
grid_location (if it's the method I should use).

Currently my code is

------------------------------Begin code---------------------------

#!/usr/bin/python

from Tkinter import *
import sys

class application:

	def click(self, event):
		print "Clicked ", event.x, event.y

	def __init__(self, master=None):
		self.master = master

		for r in range(3):
			for c in range(3):
				lbl = Label(master, text = 1000 + r + c)
				lbl.grid(row = r, column = c, sticky = NSEW)
				
root = Tk()
root.title('Parrilla horària')
g = application(root)
root.bind("<Button-1>", g.click)
root.mainloop()

----------------------------End code-----------------------------

Can anybody show me the correct way?


Thanks in advance

-- 
------------------------------------------------------------------------
Carles Sadurní Anguita    |   no había que cumplir promesas,
                          |   el cansancio era de placer,
Quita _mira_la_firma para |   las lágrimas eran de risas...
responder.                |   y parece que aún fue ayer.
                          |           Los Suaves
------------------------------------------------------------------------



More information about the Python-list mailing list