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() -- http://mail.python.org/mailman/listinfo/python-list