[Tkinter-discuss] scrolled canvas ,strange problem
contro opinion
contropinion at gmail.com
Sat Sep 3 11:31:24 CEST 2011
i have written a program in tkinter to draw stock graph,there are two
strange thing i can't understand
the attachment is 'AAU' data file(attachment 1).when you download it
,please save it in /tmp/AAU
there is a scrolled canvas in it ,
1.strang long line,please see my attachment.
i have see my data ,my formulation ,no wrong,but the line is so long!!
2.there is no motion event reaction in the right of canvas,only
motion event reaction in the left of canvas.
3.i have round function ,but the output is still more fractions than 2.
------------------ 原始邮件 ------------------
*发件人:* "John McMonagle"<jmcmonagle at velseis.com>;
*发送时间:* 2011年9月2日(星期五) 中午1:48
*收件人:* "1248283536"<1248283536 at qq.com>;
*抄送:* "Tkinter-discuss"<tkinter-discuss at python.org>;
*主题:* Re: [Tkinter-discuss] tkinter and cursor
On 02/09/11 13:59, 守株待兔 wrote:
>
> you can get a figure with the program, when you move mouse on the canvas
(figure),you can see the coordinate on the right corner , i want to make it
in tkinter,there is no "move click in the canvas" event in tkinter,how to
make it in tkinter??
>
You can use the "<Motion>" event. You also should be converting the
event.x and event.y to canvas coordinates. This is especially important
when your canvas also includes scrollbars.
So, using your code from previous posts, from the myprint function onwards,
def myprint(event):
# convert the event coordinates to canvas coordinates
x = canvas.canvasx(event.x)
y = canvas.canvasy(event.y)
# find the poistion in the top right corner of your canvas widget
# less a little bit so as to see the displayed text
cx = canvas.winfo_width() - 10
cy = 10
# delete previous displayed text
canvas.delete('coords')
# display the coordinates
canvas.create_text(cx,cy,anchor=E, text='%d,%d' % (x,y), tags='coords')
canvas.bind("<Motion>", myprint)
root.mainloop()
This will display the canvas coordinate in the top right corner of the
canvas widget.
Suggested reading on Canvas:
http://effbot.org/tkinterbook/canvas.htm
Suggested reading on events:
http://effbot.org/tkinterbook/tkinter-events-and-bindings.htm
Regarsd,
John
--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tkinter-discuss/attachments/20110903/9c7ef902/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: attach1.png
Type: image/png
Size: 69606 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/tkinter-discuss/attachments/20110903/9c7ef902/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: attach2.png
Type: image/png
Size: 56822 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/tkinter-discuss/attachments/20110903/9c7ef902/attachment-0003.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: AAU
Type: application/octet-stream
Size: 58806 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/tkinter-discuss/attachments/20110903/9c7ef902/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: draw.py
Type: text/x-python
Size: 5905 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/tkinter-discuss/attachments/20110903/9c7ef902/attachment-0001.py>
More information about the Tkinter-discuss
mailing list