Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Tkinter: how; newbie

Reply
Thread Tools

Tkinter: how; newbie

 
 
Gigs_
Guest
Posts: n/a
 
      02-13-2007
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!
 
Reply With Quote
 
 
 
 
Matimus
Guest
Posts: n/a
 
      02-13-2007

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


 
Reply With Quote
 
 
 
 
Gigs_
Guest
Posts: n/a
 
      02-14-2007
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
 
Reply With Quote
 
jim-on-linux
Guest
Posts: n/a
 
      02-14-2007
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!

 
Reply With Quote
 
Gigs_
Guest
Posts: n/a
 
      02-14-2007
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!

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
newbie with newbie questions JohnE ASP .Net 3 08-17-2009 10:10 PM
VONAGE Newbie w/newbie question New_kid@nowhere.new VOIP 0 08-11-2007 01:40 PM
another newbie question from another newbie.... Lee UK VOIP 4 05-17-2005 04:10 PM
newbie: cisco vlan newbie question No Spam Cisco 3 06-07-2004 10:02 AM
Newbie! I'm a newbie! What's wrong with this program? Id0x Python 4 07-20-2003 11:40 PM



Advertisments