tkinter, event.widget, what do i get?

Discussion in 'Python' started by skanemupp@yahoo.se, Apr 15, 2008.

  1. Guest

    when calling function hmm here, what do i get? the widget i clicked
    on?
    if i have a canvs on wich i have a bitmap and i click on the bitmap,
    is the event.widget then the bitmap?
    can i get info about the bitmap then? like color of the pixel i
    clicked. if so, how?


    w.bind("<Key>", key)
    w.bind("<Button-1>", hmm)

    def hmm(event):
    return event.widget
    , Apr 15, 2008
    #1
    1. Advertising

  2. En Tue, 15 Apr 2008 17:45:08 -0300, <> escribió:

    > when calling function hmm here, what do i get? the widget i clicked
    > on?
    > if i have a canvs on wich i have a bitmap and i click on the bitmap,
    > is the event.widget then the bitmap?
    > can i get info about the bitmap then? like color of the pixel i
    > clicked. if so, how?
    >
    >
    > w.bind("<Key>", key)
    > w.bind("<Button-1>", hmm)
    >
    > def hmm(event):
    > return event.widget


    Why don't you try by yourself? You can use: print repr(something)

    --
    Gabriel Genellina
    Gabriel Genellina, Apr 15, 2008
    #2
    1. Advertising

  3. Guest

    On 16 Apr, 00:24, "Gabriel Genellina" <> wrote:
    > En Tue, 15 Apr 2008 17:45:08 -0300, <> escribió:
    >
    > > when calling function hmm here, what do i get? the widget i clicked
    > > on?
    > > if i have a canvs on wich i have a bitmap and i click on the bitmap,
    > > is the event.widget then the bitmap?
    > > can i get info about the bitmap then? like color of the pixel i
    > > clicked. if so, how?

    >
    > > w.bind("<Key>", key)
    > > w.bind("<Button-1>", hmm)

    >
    > > def hmm(event):
    > > return event.widget

    >
    > Why don't you try by yourself? You can use: print repr(something)
    >
    > --
    > Gabriel Genellina



    i get <Tkinter.Canvas instance at 0x01B9B6E8>

    thing is i get that even though i click outside the image.
    and what can i do with this number anyway?
    , Apr 16, 2008
    #3
  4. En Tue, 15 Apr 2008 20:45:24 -0300, <> escribió:
    > On 16 Apr, 00:24, "Gabriel Genellina" <> wrote:
    >> En Tue, 15 Apr 2008 17:45:08 -0300, <> escribió:
    >>
    >> > when calling function hmm here, what do i get? the widget i clicked
    >> > on?
    >> > if i have a canvs on wich i have a bitmap and i click on the bitmap,
    >> > is the event.widget then the bitmap?
    >> > can i get info about the bitmap then? like color of the pixel i
    >> > clicked. if so, how?

    >>
    >> > w.bind("<Key>", key)
    >> > w.bind("<Button-1>", hmm)

    >>
    >> > def hmm(event):
    >> > return event.widget

    >>
    >> Why don't you try by yourself? You can use: print repr(something)

    >
    > i get <Tkinter.Canvas instance at 0x01B9B6E8>
    >
    > thing is i get that even though i click outside the image.


    So you answered your first question yourself: event.widget is the canvas,
    not the bitmap.
    On another thread you get the other answer.

    > and what can i do with this number anyway?


    With that specific number, nothing. The whole text says two things:

    - *what* the object is: a Tkinter.Canvas instance
    - *which* one: this is not the same one as <Tkinter.Canvas instance at
    0x12345678>

    --
    Gabriel Genellina
    Gabriel Genellina, Apr 16, 2008
    #4
  5. Guest

    On 16 Apr, 01:45, wrote:
    > On 16 Apr, 00:24, "Gabriel Genellina" <> wrote:
    >
    >
    >
    >
    >
    > > En Tue, 15 Apr 2008 17:45:08 -0300, <> escribió:

    >
    > > > when calling function hmm here, what do i get? the widget i clicked
    > > > on?
    > > > if i have a canvs on wich i have a bitmap and i click on the bitmap,
    > > > is the event.widget then the bitmap?
    > > > can i get info about the bitmap then? like color of the pixel i
    > > > clicked. if so, how?

    >
    > > > w.bind("<Key>", key)
    > > > w.bind("<Button-1>", hmm)

    >
    > > > def hmm(event):
    > > >     return event.widget

    >
    > > Why don't you try by yourself? You can use: print repr(something)

    >
    > > --
    > > Gabriel Genellina

    >
    > i get <Tkinter.Canvas instance at 0x01B9B6E8>
    >
    > thing is i get that even though i click outside the image.
    > and what can i do with this number anyway?- Nascondi testo tra virgolette -
    >
    > - Mostra testo tra virgolette -


    If your image is a canvas item (i.e. created with canvas create_image
    method), then you can use
    the method tag_bind to handle events specific of that item.
    In that case, the callback argument is a Tkinter.Event instance.

    Ciao
    -----
    FB
    , Apr 16, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeff Epler
    Replies:
    0
    Views:
    490
    Jeff Epler
    Aug 20, 2004
  2. Jeff Epler
    Replies:
    0
    Views:
    439
    Jeff Epler
    Aug 23, 2004
  3. Frederic Rentsch
    Replies:
    0
    Views:
    216
    Frederic Rentsch
    Jul 8, 2012
  4. Terry Reedy
    Replies:
    15
    Views:
    607
    Frederic Rentsch
    Jul 16, 2012
  5. Frederic Rentsch
    Replies:
    0
    Views:
    414
    Frederic Rentsch
    Jul 9, 2012
Loading...

Share This Page