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"<[hidden email]>; 发送时间: 2011年9月2日(星期五) 中午1:48
收件人: "1248283536"<[hidden email]>; 抄送: "Tkinter-discuss"<[hidden email]>;
主题: Re: [Tkinter-discuss] tkinter and cursor > > 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. _______________________________________________ Tkinter-discuss mailing list [hidden email] http://mail.python.org/mailman/listinfo/tkinter-discuss ![]() ![]() ![]() ![]() |
On Sat, 3 Sep 2011 17:31:24 +0800, contro opinion wrote
> 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!! > I haven't analysed it thoroughly, but your horizontal scale for the data does not match the horizontal scale for your labels or motion reporting. The "long line" you see actually matches the data on line 1089 in your data file. The date on this line is 2007-02-27. > 2.there is no motion event reaction in the right of canvas,only > motion event reaction in the left of canvas. The IS a motion event throughout the entire canvas. Again, your problem seems to be with your horizontal scale. The far right coordinate is 5710, yet you only report the motion to 2764, the upper limit of self.xsqueen. > 3.i have round function ,but the output is still more fractions than 2. Whether you round a float or not has no impact on how it is displayed as a string. You need to use the appropriate string formatting. If you want two decimal places try the following format: %.2f rather than %f. The rounding will also be properly handled by the string formatting, so there will be no need to use the round function. Regards, John -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. _______________________________________________ Tkinter-discuss mailing list [hidden email] http://mail.python.org/mailman/listinfo/tkinter-discuss |
In reply to this post by contro opinion
think for John McMonagle
only one sentence is wrong ,i revise it : self.xsqueen=[50+4*i for i in range(0,self.pairs)] it is ok,now ^_^ 在 2011年9月3日 下午5:31,contro opinion <[hidden email]>写道: i have written a program in tkinter to draw stock graph,there are two strange thing i can't understand _______________________________________________ Tkinter-discuss mailing list [hidden email] http://mail.python.org/mailman/listinfo/tkinter-discuss |
In reply to this post by contro opinion
i want to save my phote in computer,so i add
canvas.postscript(file="mystock.eps") there is a file named mystock.eps,but nothing in it! I want to know how to save my canvas as an image file. ------------------ Original ------------------ From: "johnmc"<[hidden email]>; Date: Sun, Sep 4, 2011 11:26 AM To: "contro opinion"<[hidden email]>; "John McMonagle"<[hidden email]>; "Tkinter-discuss"<[hidden email]>; Subject: Re: [Tkinter-discuss] scrolled canvas ,strange problem > 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!! > I haven't analysed it thoroughly, but your horizontal scale for the data does not match the horizontal scale for your labels or motion reporting. The "long line" you see actually matches the data on line 1089 in your data file. The date on this line is 2007-02-27. > 2.there is no motion event reaction in the right of canvas,only > motion event reaction in the left of canvas. The IS a motion event throughout the entire canvas. Again, your problem seems to be with your horizontal scale. The far right coordinate is 5710, yet you only report the motion to 2764, the upper limit of self.xsqueen. > 3.i have round function ,but the output is still more fractions than 2. Whether you round a float or not has no impact on how it is displayed as a string. You need to use the appropriate string formatting. If you want two decimal places try the following format: %.2f rather than %f. The rounding will also be properly handled by the string formatting, so there will be no need to use the round function. Regards, John -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. _______________________________________________ Tkinter-discuss mailing list [hidden email] http://mail.python.org/mailman/listinfo/tkinter-discuss _______________________________________________ Tkinter-discuss mailing list [hidden email] http://mail.python.org/mailman/listinfo/tkinter-discuss |
Free forum by Nabble | Edit this page |