-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdraw.py
More file actions
29 lines (22 loc) · 846 Bytes
/
draw.py
File metadata and controls
29 lines (22 loc) · 846 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from Tkinter import *
class PaintBox( Frame ):
def __init__( self ):
Frame.__init__( self )
self.pack( expand = YES, fill = BOTH )
self.master.title( "A simple paint program" )
self.master.geometry( "300x150" )
self.message = Label( self, text = "Drag the mouse to draw" )
self.message.pack( side = BOTTOM )
# create Canvas component
self.myCanvas = Canvas( self )
self.myCanvas.pack( expand = YES, fill = BOTH )
# bind mouse dragging event to Canvas
self.myCanvas.bind( "<B1-Motion>", self.paint )
def paint( self, event ):
x1, y1 = ( event.x - 4 ), ( event.y - 4 )
x2, y2 = ( event.x + 4 ), ( event.y + 4 )
self.myCanvas.create_oval( x1, y1, x2, y2, fill = "red" )
def main():
PaintBox().mainloop()
if __name__ == "__main__":
main()