Last active
December 2, 2020 13:21
-
-
Save hccho2/a870bf5b9524ec88ce076a73bb050226 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PIL import ImageTk, Image, ImageDraw | |
import PIL | |
from tkinter import * | |
import os | |
width = 200 | |
height = 200 | |
center = height//2 | |
white = (255, 255, 255) | |
black = (0,0,0) | |
green = (0,128,0) | |
def save(): | |
j=0 | |
filename = "image" + str(j) + ".png" | |
while os.path.exists(filename): | |
j += 1 | |
filename = "image" + str(j) + ".png" | |
image1.save(filename) | |
def clear(): | |
... | |
def paint(event): | |
x1, y1 = (event.x - 1), (event.y - 1) | |
x2, y2 = (event.x + 1), (event.y + 1) | |
cv.create_oval(x1, y1, x2, y2, fill="white",width=20) # 저장되는 color | |
draw.line([x1, y1, x2, y2],fill="white",width=20) | |
root = Tk() | |
# Tkinter create a canvas to draw on | |
cv = Canvas(root, width=width, height=height, bg='white') | |
cv.pack() | |
image1 = PIL.Image.new("RGB", (width, height), black) # 저장되는 backgroudn color | |
draw = ImageDraw.Draw(image1) | |
cv.pack(expand=YES, fill=BOTH) | |
cv.bind("<B1-Motion>", paint) | |
button1=Button(text="save",command=save) | |
button2=Button(text="clear",command=clear) | |
button1.pack() | |
button2.pack() | |
print(image1) | |
root.mainloop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment