How to use grid_location (Tkinter)

John Grayson johngrayson at home.com
Thu Aug 24 13:32:54 EDT 2000


In article <slrn8qabvp.16u.isard at localhost.localdomain>,
  sadurni_mira_la_firma at jazzfree.com wrote:
> 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).
>

--snip--

Try this:

#!/usr/bin/python

from Tkinter import *
import sys

class application:

    def click(self, event):
        print "Clicked ", event.widget.grid_info()['row'], \
                          event.widget.grid_info()['column']

    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()


   John Grayson


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



More information about the Python-list mailing list