# w2tk.py from Tkinter import * root=Tk() root.title('w2tk.py') print 'w2tk.py connect points' xp=[0 for i in range(100)] yp=[0 for i in range(100)] n=0 npoints=0 def redraw(): # because I am using c.delete(ALL) global c c.create_line( 20, 40, 20,350,fill='black') c.create_line( 20,350,380,350,fill='black') c.create_line(380,350,380, 40,fill='black') c.create_line(380, 40, 20, 40,fill='black') c.create_text( 200, 20, text='press button 1 for point. button 3 to connect',fill='black') c.create_text(200, 380, text='click here to exit', fill='black') def mouseB1press(event): # left global xp, yp, n, npoints print 'mouse B1 press x=', event.x, ', y=', event.y if event.y>350: sys.exit() if event.y<40: return if n>0 : npoints=0 n=0 c.delete(ALL) redraw() x=event.x xp[npoints]=x y=event.y yp[npoints]=event.y c.create_oval(x-2,y-1,x+2,y+2,fill='red') npoints=npoints+1 def mouseB3press(event): # right global xp, yp, n, npoints print 'mouse B3 press ' for i in range(npoints-1): #connect every point to every other for j in range(npoints): c.create_line(xp[i], yp[i], xp[j], yp[j], fill='blue'); n=npoints c=Canvas(root, width=400, height=400, bg='white') c.bind('' , mouseB1press) c.bind('' , mouseB3press) redraw() c.pack() root.mainloop()