Add b&w and mirror button and features

Fix #8
Fix #7
This commit is contained in:
Clement Desmidt 2023-05-23 17:42:42 +02:00
parent cac19935f3
commit fa13377c14
2 changed files with 33 additions and 5 deletions

View File

@ -1,7 +1,6 @@
import random import random
from tkinter import * from tkinter import *
from PIL import ImageTk, Image from PIL import ImageTk, Image, ImageOps
from util import Util from util import Util
@ -10,6 +9,10 @@ class ImageWindow:
self.window = Toplevel(window) self.window = Toplevel(window)
self.window.title("Image") self.window.title("Image")
self.window.geometry("1280x1024") self.window.geometry("1280x1024")
self.option = {
"bw": False,
"mirror": False
}
self.images = [] self.images = []
self.current_image = None self.current_image = None
self.image_label = None self.image_label = None
@ -18,12 +21,20 @@ class ImageWindow:
self.timer = 0 self.timer = 0
self.timer_label = None self.timer_label = None
self.timer_check = None self.timer_check = None
next_button = Button(toolbar, relief=FLAT, compound=LEFT, text="next ➡️", command=self.next_image) next_button = Button(toolbar, relief=FLAT, compound=LEFT, text="next ➡️", command=self.next_image)
next_button.pack(side=LEFT, padx=0, pady=0) 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 = 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 = Label(toolbar, text=self.timer)
self.timer_label.pack(side=BOTTOM) self.timer_label.pack(side=RIGHT, ipadx=20)
def update_timer(self, current): def update_timer(self, current):
current -= 1 current -= 1
@ -45,6 +56,16 @@ class ImageWindow:
self.display_new_image() self.display_new_image()
self.display_new_timer() 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): def lets_draw(self, images, timer):
random.shuffle(images) random.shuffle(images)
self.images = images self.images = images
@ -66,6 +87,12 @@ class ImageWindow:
self.resize_image() 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) image_to_display = ImageTk.PhotoImage(self.current_image)
self.image_label.configure(image=image_to_display) self.image_label.configure(image=image_to_display)
@ -81,6 +108,7 @@ class ImageWindow:
w = 1280 w = 1280
h = 1024 h = 1024
self.current_image.thumbnail((w - 20, h - 20), Image.ANTIALIAS) self.current_image.thumbnail((w - 20, h - 20), Image.ANTIALIAS)
print("resized: win %s >= img %s", (w, h), self.current_image.size) print("resized: win %s >= img %s", (w, h), self.current_image.size)
image_to_display = ImageTk.PhotoImage(self.current_image) image_to_display = ImageTk.PhotoImage(self.current_image)

View File

@ -7,7 +7,7 @@ def main():
root.title("Drawing Training!") root.title("Drawing Training!")
root.geometry("300x600") root.geometry("300x600")
app = App(root) App(root)
root.mainloop() root.mainloop()