-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui.py
More file actions
57 lines (44 loc) · 1.28 KB
/
ui.py
File metadata and controls
57 lines (44 loc) · 1.28 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from PIL import ImageTk, Image, ImageDraw
import PIL
from tkinter import *
width = 128
height = 128
center = height//2
white = (255, 255, 255)
green = (0,128,0)
cv = None
image1 = None
draw = None
root = None
def save():
filename = "image.png"
image1.save(filename)
root.destroy()
def paint(event):
# python_green = "#476042"
x1, y1 = (event.x - 1), (event.y - 1)
x2, y2 = (event.x + 1), (event.y + 1)
print(cv)
cv.create_oval(x1, y1, x2, y2, fill="black",width=5)
draw.line([x1, y1, x2, y2],fill="black",width=5)
root = Tk()
# Tkinter create a canvas to draw on
cv = Canvas(root, width=width, height=height, bg='white')
cv.pack()
# PIL create an empty image and draw object to draw on
# memory only, not visible
image1 = PIL.Image.new("RGB", (width, height), white)
draw = ImageDraw.Draw(image1)
# do the Tkinter canvas drawings (visible)
# cv.create_line([0, center, width, center], fill='green')
cv.pack(expand=YES, fill=BOTH)
cv.bind("<B1-Motion>", paint)
# do the PIL image/draw (in memory) drawings
# draw.line([0, center, width, center], green)
# PIL image can be saved as .png .jpg .gif or .bmp file (among others)
# filename = "my_drawing.png"
# image1.save(filename)
button=Button(text="save",command=save)
button.pack()
def init():
root.mainloop()