parent
cac19935f3
commit
fa13377c14
36
image.py
36
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)
|
||||
|
Loading…
Reference in New Issue
Block a user