Tkinter: how; newbie

G

Gigs_

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!
 
M

Matimus

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/
 
G

Gigs_

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


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
 
J

jim-on-linux

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.
 
G

Gigs_

jim-on-linux said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top