From fa13377c14cb67ecec7a131b55f2124aba0ff307 Mon Sep 17 00:00:00 2001 From: Clement Desmidt Date: Tue, 23 May 2023 17:42:42 +0200 Subject: [PATCH] :sparkles: Add b&w and mirror button and features Fix #8 Fix #7 --- image.py | 36 ++++++++++++++++++++++++++++++++---- main.py | 2 +- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/image.py b/image.py index 18880cb..797213b 100644 --- a/image.py +++ b/image.py @@ -1,7 +1,6 @@ import random from tkinter import * -from PIL import ImageTk, Image - +from PIL import ImageTk, Image, ImageOps from util import Util @@ -10,6 +9,10 @@ class ImageWindow: self.window = Toplevel(window) self.window.title("Image") self.window.geometry("1280x1024") + self.option = { + "bw": False, + "mirror": False + } self.images = [] self.current_image = None self.image_label = None @@ -18,12 +21,20 @@ class ImageWindow: self.timer = 0 self.timer_label = None self.timer_check = None + next_button = Button(toolbar, relief=FLAT, compound=LEFT, text="next ➡️", command=self.next_image) next_button.pack(side=LEFT, padx=0, pady=0) + + bw_button = Button(toolbar, relief=FLAT, compound=LEFT, text="black&white", command=self.toggle_black_white) + bw_button.pack(side=LEFT, padx=0, pady=0) + + mirror_button = Button(toolbar, relief=FLAT, compound=LEFT, command=self.toggle_mirror, text="mirror") + mirror_button.pack(side=LEFT, padx=0, pady=0) + self.image_label = Label(self.window) - self.image_label.pack(side="top", fill="both", expand=1) + self.image_label.pack(side=TOP, fill=BOTH, expand=1) self.timer_label = Label(toolbar, text=self.timer) - self.timer_label.pack(side=BOTTOM) + self.timer_label.pack(side=RIGHT, ipadx=20) def update_timer(self, current): current -= 1 @@ -45,6 +56,16 @@ class ImageWindow: self.display_new_image() self.display_new_timer() + def toggle_black_white(self): + print("bw was " + str(self.option["bw"])) + self.option["bw"] = not self.option["bw"] + print("bw is now " + str(self.option["bw"])) + + def toggle_mirror(self): + print("mirror was " + str(self.option["mirror"])) + self.option["mirror"] = not self.option["mirror"] + print("mirror is now " + str(self.option["mirror"])) + def lets_draw(self, images, timer): random.shuffle(images) self.images = images @@ -66,6 +87,12 @@ class ImageWindow: self.resize_image() + if self.option["bw"]: + self.current_image = self.current_image.convert("L") + + if self.option["mirror"]: + self.current_image = ImageOps.mirror(self.current_image) + image_to_display = ImageTk.PhotoImage(self.current_image) self.image_label.configure(image=image_to_display) @@ -81,6 +108,7 @@ class ImageWindow: w = 1280 h = 1024 self.current_image.thumbnail((w - 20, h - 20), Image.ANTIALIAS) + print("resized: win %s >= img %s", (w, h), self.current_image.size) image_to_display = ImageTk.PhotoImage(self.current_image) diff --git a/main.py b/main.py index 65c674c..efac809 100644 --- a/main.py +++ b/main.py @@ -7,7 +7,7 @@ def main(): root.title("Drawing Training!") root.geometry("300x600") - app = App(root) + App(root) root.mainloop() -- 2.30.2