473,326 Members | 2,126 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

drawline

I had the following code and when I clicked the left mouse button one
time. I got green line and the second click got a purple line and the
green disappeared.
I was confused by two questions:
First, Clicknum increases when every time I click the button. Is it
possible to reset Clicknum to 0?
Second, how to do something like: I click the left button the first
time, the green line appear then disappear, the purple line
appear(just as the code has done but become a loop; if a second-time
click is implied, the loop stops.
from Tkinter import *

ClickNum = 0

def drawline(event):
global ClickNum
if ClickNum == 0:
canvas.create_line(100, 0, 100, 200, arrow=FIRST,fill="green",tag="a")
elif ClickNum == 1:
canvas.delete("a")
canvas.create_line(100, 50, 60, 300, arrow=FIRST,fill="purple")
ClickNum += 1

tk = Tk()
canvas = Canvas(tk, bg="white", bd=0, highlightthickness=0)
canvas.pack(fill=BOTH, expand=YES)
canvas.create_line(100, 200, 350, 200, arrow=LAST,fill='red')
canvas.bind("<1>", drawline)
tk.mainloop()
Nov 22 '05 #1
3 3153
Hi Ben,
if I understood your questions properly, this code gives some answers (on
XP):

from Tkinter import *

lines = [
[ (100, 200, 350, 200), LAST, "red", '' ],
[ (100, 0, 100, 200), FIRST, "green", 'a' ],
[ (100, 200, 300, 100), LAST, "purple", 'b' ],
]

ClickMax = len(lines)
ClickNum = 0
lasttag = ''

def drawline(event):
global ClickNum,lasttag
canvas.delete(lasttag)
line = lines[ClickNum]
canvas.create_line(line[0], arrow=line[1], fill=line[2],tag=line[3])
lasttag = line[3]
ClickNum = (ClickNum+1) % ClickMax
ClickNum = ClickNum or 1

canvas = Canvas(Tk(), bg="white", bd=0, highlightthickness=0)
canvas.pack(fill=BOTH, expand=YES)
drawline(0)
canvas.bind("<1>", drawline)
canvas.mainloop()

Eugene
"Ben Bush" <py*******@gmail.com> wrote in message
news:ma***************************************@pyt hon.org...
I had the following code and when I clicked the left mouse button one
time. I got green line and the second click got a purple line and the
green disappeared.
I was confused by two questions:
First, Clicknum increases when every time I click the button. Is it
possible to reset Clicknum to 0?
Second, how to do something like: I click the left button the first
time, the green line appear then disappear, the purple line
appear(just as the code has done but become a loop; if a second-time
click is implied, the loop stops.
from Tkinter import *

ClickNum = 0

def drawline(event):
global ClickNum
if ClickNum == 0:
canvas.create_line(100, 0, 100, 200,
arrow=FIRST,fill="green",tag="a")
elif ClickNum == 1:
canvas.delete("a")
canvas.create_line(100, 50, 60, 300, arrow=FIRST,fill="purple")
ClickNum += 1

tk = Tk()
canvas = Canvas(tk, bg="white", bd=0, highlightthickness=0)
canvas.pack(fill=BOTH, expand=YES)
canvas.create_line(100, 200, 350, 200, arrow=LAST,fill='red')
canvas.bind("<1>", drawline)
tk.mainloop()
Nov 23 '05 #2
Ben Bush wrote:
I had the following code and when I clicked the left mouse button one
time. I got green line and the second click got a purple line and the
green disappeared.
I was confused by two questions:


It's good that these postings are archived, so that teachers can
check them before grading their students. After all, the grades
belong to those who solved the problems, not to those who handed
them in...
Nov 23 '05 #3
On 11/23/05, Magnus Lycka <ly***@carmen.se> wrote:
Ben Bush wrote:
I had the following code and when I clicked the left mouse button one
time. I got green line and the second click got a purple line and the
green disappeared.
I was confused by two questions:


It's good that these postings are archived, so that teachers can
check them before grading their students. After all, the grades
belong to those who solved the problems, not to those who handed
them in...

I learned Python by myself and not seeking to hand in these results
for anyone. All the questions are not from any textbook. Please be
polite and do not assume something just in your mind.
Nov 26 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jon Cosby | last post by:
I'm using this to draw rectangles in a PictureBox image. Not all of the rectangles are complete, and after drawing several, some of them start disapearing. What's the reason for this? Pen...
1
by: Rich | last post by:
Hello, I am trying to draw a graph on a form. I can draw the box using drawline, and bars inside the box using drawrectangle, but when I try to draw a line inside the box the inner lines are...
4
by: Smoke | last post by:
It is possible to draw a line on a control using AA? basically, i need the normal .DrawLine funcion but that support antia aliasing. is this possible? can somebody tellme how? Thanks for the...
2
by: google_groups3 | last post by:
Hi, is it better practise to draw a line on my form using the Graphics.DrawLine command or should I use a label control instead? I am refering to overall speed of the form and amount of memory...
2
by: John | last post by:
I created a number of pictureboxes in a panel, and want to draw lines in those pictureboxes but I cannot. Please see the following code and make corrections. Thanks. Private Sub...
0
by: Lila Godel | last post by:
I am migrating my VB6 GoldMine add-ons to VB.NET to allow for enhancements. I have no problem getting text to print, but I cannot get the 4 PrintPage events that are needed to print a line to work....
2
by: Stu | last post by:
Hi, Why does the code below only draw the last line of the loop? I was expecting this to draw 10 parallel lines. More to the piont....how do I get it to draw 10 parallel lines? Public...
2
by: intrepid_dw | last post by:
All I am writing a C# WinForms application which is giving me some problems. The application consists of a form containing an empty Tab control to which TabPages are added dynamically (at...
2
by: RichGK | last post by:
This is from http://msdn2.microsoft.com/en-us/library/aa287522(VS.71).aspx public MainForm() { InitializeComponent(); System.Drawing.Pen myPen;
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.