-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdraw.py
38 lines (30 loc) · 853 Bytes
/
draw.py
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
30
31
32
33
34
35
36
37
38
#Christina Roberts
#How to Code 2.0
from tkinter import*
my_pen = "up"
my_x, my_y = None, None
def main():
root = Tk()
my_sketch = Canvas(root)
my_sketch.pack()
my_sketch.bind("<Motion>", motion)
my_sketch.bind("<ButtonPress-1>", my_pen_down)
my_sketch.bind("<ButtonRelease-1>", my_pen_up)
root.mainloop()
def my_pen_down(event):
global my_pen
my_pen = "down"
def my_pen_up(event):
global my_pen, my_x, my_y
my_pen = "up"
my_x = None
my_y = None
def motion(event):
global my_x, my_y
if my_pen == "down":
if my_x is not None and my_y is not None:
event.widget.create_line(my_x, my_y, event.x, event.y, smooth = True)
my_x = event.x
my_y = event.y
print("Use cursor to draw in field provided please.")
main()