Tkinter design problem

Greg Krohn volucris at hotmail.com
Sun Sep 2 19:39:17 EDT 2001


If you bind your callback it sends back an event argument that has
the 'widget' attribute. That is the widget that called it.


from Tkinter import *

def handler(event):
    print 'You pressed row %d, column %d.' %\
          (buttons[event.widget][0], (buttons[event.widget][0]))

root = Tk()

buttons = {}

for x in range(4):
    for y in range(3):
        b = Button(root, text='%d, %d' % (x, y))
        buttons[b] = [x, y]
        b.grid(row=y, column=x)
        b.bind('<Button>', handler)

root.mainloop()




This is storing the buttons in a dictionary, so maybe this is what you were
talking about in the first place. If so, I don't know of a better way. If
not, I hope this helps.
--

Volucris (a) hotmail.com
"Eu não falo uma única palavra do português."


"Janos Blazi" <jblazi at hotmail.com> wrote in message
news:3b92af17_8 at news.newsgroups.com...
> Suppose I have a table realized az an array of buttons. It seems sensible
> that all buttons are bound to the sam callback procedure. But the callback
> proc must know which button has been pushed, i.e. the row and the column.
> Now of course I could set up a dictionary with the buttons as keys and the
> row and the column. But is it the right way of solving this problem? Is
> there a simpler solution?
>
> Janos Blazi
>
>
>
>
> -----=  Posted via Newsfeeds.Com, Uncensored Usenet News  =-----
> http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
>  Check out our new Unlimited Server. No Download or Time Limits!
> -----==  Over 80,000 Newsgroups - 19 Different Servers!  ==-----





More information about the Python-list mailing list