[Tkinter-discuss] 回复: get root.winfo_pointerxy()
守株待兔
1248283536 at qq.com
Fri Sep 2 04:18:23 CEST 2011
in my program,myprint is:
def myprint(arg):
x=arg.x
y=arg.y
canvas.create_text(x,y,text='i am here')
canvas.bind("<Button-1>",myprint)
now ,when i left click mouse on the point in then canvas first time, there is output: i am here
when i left click mouse on the point in then canvas second time,there is output too:i am here
what i want to get is :
when i left click mouse on the point in then canvas second time,the old output (i am here) disappear,
only new output (i am here) in the canvas,how to do ?
any advice appreciated.
------------------ 原始邮件 ------------------
发件人: "Cameron Laird"<Cameron at phaseit.net>;
发送时间: 2011年9月1日(星期四) 晚上11:19
收件人: "Douglas S. Blank"<dblank at cs.brynmawr.edu>;
抄送: "tkinter-discuss"<tkinter-discuss at python.org>;
主题: Re: [Tkinter-discuss] get root.winfo_pointerxy()
On Thu, Sep 01, 2011 at 10:37:31AM -0400, Douglas S. Blank wrote:
.
.
.
> On 09/01/2011 10:21 AM, wrote:
> >def myprint():
> > print root.winfo_pointerxy()
> >
> >canvas.bind("<Button-1>",myprint)
>
> When you bind a function to the canvas, it is expecting a function that
> takes an argument (which is probably the object to which the binding is
> bound).
>
> So, you could just allow myprint to take an argument, and ignore it:
>
> def myprint(arg):
> print root.winfo_pointerxy()
.
.
.
I entirely agree with the counsel Dr. Blank has provided.
While I expect the original questioner has all he needs to
move forward, I'll provide a bit more detail for the
benefit of other readers.
Let's look at "arg", "which is probably the object to
which the binding is bound". It's not; it's the detected
*event* (from which that object can be calculated, though)
<URL: http://www.pythonware.com/library/tkinter/introduction/events-and-bindings.htm >.
That's not all. One could temporarily update myprint's
definition to be something like
def myprint(arg):
print "arg is '%s'." % arg
print dir(arg)
print root.winfo_pointerxy()
to have Python's introspection report more information
about the argument.
And *that* isn't all, either. If one were somehow
stranded-on-a-desert-island and unsure how many (not-
necessarily-named) arguments were arriving, one could
experiment with
def myprint(*kw):
print kw
...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tkinter-discuss/attachments/20110902/90070164/attachment.html>
More information about the Tkinter-discuss
mailing list