Jun-17-2020, 10:10 AM
(This post was last modified: Jun-17-2020, 10:10 AM by foksikrasa.)
I and my tutor have been working on this project but it doesn't work. Even he can't find the error please help
.
(It is supposed to let you draw and then save your picture)
Many thanks,
foksikrasa

(It is supposed to let you draw and then save your picture)
Many thanks,
foksikrasa
from tkinter import * from PIL import Image, ImageDraw import io import os import subprocess canvas_width = 1000 canvas_height = 1000 color = 'black' brush_size = 1 def paint(event): global brush_size global color x1 = event.x - brush_size x2 = event.x + brush_size y1 = event.y - brush_size y2 = event.y + brush_size w.create_oval(x1, y1, x2, y2, fill = color, outline=color) def save_as_gpg(): # saveIMG() print("Picture saving...") w.postscript(file = "Picture.eps", colormode='color') img = Image.open("Picture.eps") # draw = ImageDraw.Draw(img) # draw.text((10, 20), "Chao!", (0, 0, 0)) img.save("Picture.png", "png") def brush_size_change(new_brush_size): global brush_size brush_size += new_brush_size if brush_size < 1: brush_size = 1 set_brush_size(brush_size) def color_change(new_color): global color color = new_color def set_brush_size(new_brush_size): brush_label.configure(text = "brush = " + str(new_brush_size)) def update_brush_size_from_entry(): global brush_size brush_size = int(b_entry.get()) if brush_size < 1: brush_size = 1 set_brush_size(brush_size) def saveIMG(): print("Picture saving...") w.update() w.postscript(file = 'Picture.eps', colormode = "color") root = Tk() root.title('Paint') w = Canvas(root, width = canvas_width, height = canvas_height, bg='white') w.bind('<B1-Motion>', paint) w.grid(row=2, column=5) w.columnconfigure(6, weight=1) w.rowconfigure(2, weight=1) red_btn = Button(text='Красный цвет', width=10, command = lambda: color_change('red'), bg = 'red') red_btn.grid(row = 0, column=6) Black_btn = Button(text='чёрный', width=10, command = lambda: color_change('black'), bg = 'black') Black_btn.grid(row = 0, column=1) Purple_btn = Button(text='фиолетовый', width=10, command = lambda: color_change('purple'), bg = 'purple') Purple_btn.grid(row = 0, column=2) Blue_btn = Button(text='синий', width=10, command = lambda: color_change('blue'), bg = 'blue') Blue_btn.grid(row = 0, column=3) green_btn = Button(text='Зеленый', width=10, command = lambda: color_change('green'), bg = 'green') green_btn.grid(row = 0, column=4) Orange_btn = Button(text='оранжевый', width=10, command = lambda: color_change('orange'), bg = 'orange') Orange_btn.grid(row = 0, column=7) Yellow_btn = Button(text='желтый', width=10, command = lambda: color_change('yellow'), bg = 'yellow') Yellow_btn.grid(row = 0, column=8) white_btn = Button(text='Ластик', width=10, command = lambda: color_change('white'), bg = 'white') white_btn.grid(row = 0, column=9) clear_btn = Button(text='Стереть все', width=10, command = lambda: w.delete('all')) clear_btn.grid(row=0,column=5) brush_plus = Button(text='Bigger', width=10, command = lambda: brush_size_change(1)) brush_plus.grid(row=3,column=1) brush_minus = Button(text='Smaller', width=10, command = lambda: brush_size_change(-1)) brush_minus.grid(row=3,column=2) b_entry = Entry(root, width = 10) b_entry.grid(row=3,column=4) update_brush_size = Button(text='Update', width=10, command = lambda: update_brush_size_from_entry()) update_brush_size.grid(row=3,column=5) save_btn = Button(text='Save', width=10, command = lambda: save_as_gpg()) save_btn.grid(row=3,column=6) brush_label = Label(root, width=10, text = "brush =") brush_label.grid(row=3,column=3) root.mainloop()