Tkinter: how; newbie

Discussion in 'Python' started by Gigs_, Feb 13, 2007.

  1. Gigs_

    Gigs_ Guest

    can someone explain me this code?

    from Tkinter import *

    root = Tk()

    def callback(event):
    print "clicked at", event.x, event.y

    frame = Frame(root, width=100, height=100)
    frame.bind("<Button-1>", callback)
    frame.pack()

    root.mainloop()


    well, my problem is at frame.bind(",Button-1>", callback)
    callback function prints event.x and event.y.
    How the callback function get this two number when it has only one
    argument (event)
    Why its not: def callback(x, y): print x, y

    Im new to gui programming

    Sorry for bad eng!

    Thanks for replay!
    Gigs_, Feb 13, 2007
    #1
    1. Advertising

  2. Gigs_

    Matimus Guest


    > How the callback function get this two number when it has only one
    > argument (event)?


    It has one argument, event, which is an instance of a class that has
    both x and y attributes.

    > print "clicked at", event.x, event.y


    It doesn't accept the coordinates as separate parameters because every
    event binding uses that same signature, even ones for which
    coordinates might not make any sense. I recommend you look over the
    python tutorial: http://docs.python.org/tut/
    Matimus, Feb 13, 2007
    #2
    1. Advertising

  3. Gigs_

    Gigs_ Guest

    Matimus wrote:
    >> How the callback function get this two number when it has only one
    >> argument (event)?

    >
    > It has one argument, event, which is an instance of a class that has
    > both x and y attributes.
    >
    >> print "clicked at", event.x, event.y

    >
    > It doesn't accept the coordinates as separate parameters because every
    > event binding uses that same signature, even ones for which
    > coordinates might not make any sense. I recommend you look over the
    > python tutorial: http://docs.python.org/tut/
    >
    >

    that was fast, thanks
    Gigs_, Feb 14, 2007
    #3
  4. Gigs_

    jim-on-linux Guest

    On Tuesday 13 February 2007 18:02, Gigs_ wrote:
    > can someone explain me this code?
    >
    > from Tkinter import *
    >
    > root = Tk()
    >
    > def callback(event):
    > print "clicked at", event.x, event.y
    >
    > frame = Frame(root, width=100, height=100)
    > frame.bind("<Button-1>", callback)
    > frame.pack()
    >
    > root.mainloop()
    >

    if you live on longititude 32, wrere is that?
    If you live on latitude 40 and longitiude 32 I can
    find that location.

    Your mouse is pointing to x, and y, which is
    simply a location on the screen.


    >
    > well, my problem is at frame.bind(",Button-1>",
    > callback) callback function prints event.x and
    > event.y. How the callback function get this two
    > number when it has only one argument (event)
    > Why its not: def callback(x, y): print x, y
    >
    > Im new to gui programming
    >
    > Sorry for bad eng!
    >
    > Thanks for replay!
    jim-on-linux, Feb 14, 2007
    #4
  5. Gigs_

    Gigs_ Guest

    jim-on-linux wrote:
    > On Tuesday 13 February 2007 18:02, Gigs_ wrote:
    >> can someone explain me this code?
    >>
    >> from Tkinter import *
    >>
    >> root = Tk()
    >>
    >> def callback(event):
    >> print "clicked at", event.x, event.y
    >>
    >> frame = Frame(root, width=100, height=100)
    >> frame.bind("<Button-1>", callback)
    >> frame.pack()
    >>
    >> root.mainloop()
    >>

    > if you live on longititude 32, wrere is that?
    > If you live on latitude 40 and longitiude 32 I can
    > find that location.
    >
    > Your mouse is pointing to x, and y, which is
    > simply a location on the screen.
    >

    I know that, Matimus has explained what I didn't get
    but thx anyway
    >
    >> well, my problem is at frame.bind(",Button-1>",
    >> callback) callback function prints event.x and
    >> event.y. How the callback function get this two
    >> number when it has only one argument (event)
    >> Why its not: def callback(x, y): print x, y
    >>
    >> Im new to gui programming
    >>
    >> Sorry for bad eng!
    >>
    >> Thanks for replay!
    Gigs_, Feb 14, 2007
    #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:
    496
    Jeff Epler
    Aug 20, 2004
  2. Jeff Epler
    Replies:
    0
    Views:
    443
    Jeff Epler
    Aug 23, 2004
  3. Pierre Dagenais
    Replies:
    0
    Views:
    297
    Pierre Dagenais
    Aug 3, 2008
  4. Hidekazu IWAKI
    Replies:
    1
    Views:
    366
    Peter Otten
    Dec 14, 2009
  5. Hidekazu IWAKI
    Replies:
    0
    Views:
    516
    Hidekazu IWAKI
    Dec 15, 2009
Loading...

Share This Page