Last active
April 28, 2019 19:22
-
-
Save r-malon/7728e4084ef95ae92fa3e315a2c227a1 to your computer and use it in GitHub Desktop.
Image Editor Sketch
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 tkinter import * | |
from tkinter import messagebox | |
from tkinter import filedialog | |
from PIL import ImageGrab | |
def locate(event): | |
global x | |
global y | |
x = event.x | |
y = event.y | |
def draw(event): | |
canvas.create_line(x, y, event.x, event.y, fill="black", width=3) | |
locate(event) | |
def get_img(event): | |
x1 = root.winfo_rootx() + widget.winfo_x() | |
y1 = root.winfo_rooty() + widget.winfo_y() | |
x2 = x + widget.winfo_width() | |
y2 = y + widget.winfo_height() | |
ImageGrab.grab().crop((x1,y1,x2,y2)).save("file.png") #Windows only | |
def maximize(event): | |
root.attributes("-fullscreen", True) | |
root.bind("<F11>", minimize) | |
def minimize(event): | |
root.attributes("-fullscreen", False) | |
root.bind("<F11>", maximize) | |
root = Tk() | |
root.geometry("600x480") | |
menu = Menu(root) | |
canvas = Canvas(root, cursor="cross") | |
root.bind("<F11>", maximize) | |
canvas.bind("<Motion>", locate) | |
canvas.bind("<B1-Motion>", draw) | |
root.bind("<Control-S>", get_img) | |
if __name__ == '__main__': | |
canvas.pack(fill="both", expand=True) | |
root.config(menu=menu) | |
root.mainloop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment