From cac19935f3b4a0a9cae50120beb844e742464fdc Mon Sep 17 00:00:00 2001 From: Clement Desmidt Date: Tue, 23 May 2023 13:39:16 +0200 Subject: [PATCH] :sparkles: Add next button Fix #2 --- image.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/image.py b/image.py index 640c1ba..18880cb 100644 --- a/image.py +++ b/image.py @@ -13,12 +13,16 @@ class ImageWindow: self.images = [] self.current_image = None self.image_label = None + toolbar = Frame(self.window, bd=1, relief=RAISED) + toolbar.pack(side=BOTTOM, fill=X) 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) self.image_label = Label(self.window) self.image_label.pack(side="top", fill="both", expand=1) - self.timer_label = Label(self.window, text=self.timer) + self.timer_label = Label(toolbar, text=self.timer) self.timer_label.pack(side=BOTTOM) def update_timer(self, current): @@ -33,8 +37,13 @@ class ImageWindow: self.window.update() return - self.display_new_image() - self.display_new_timer() + self.next_image() + + def next_image(self): + if self.timer_check is not None: + self.window.after_cancel(self.timer_check) + self.display_new_image() + self.display_new_timer() def lets_draw(self, images, timer): random.shuffle(images) @@ -44,8 +53,7 @@ class ImageWindow: # canvas = Canvas(self.window) # canvas.pack(fill=BOTH, expand=1) - self.display_new_image() - self.display_new_timer() + self.next_image() def display_new_timer(self): self.timer_label.configure(text=self.timer) @@ -56,6 +64,8 @@ class ImageWindow: self.images.pop(0) self.current_image = Image.open(image_path) + self.resize_image() + image_to_display = ImageTk.PhotoImage(self.current_image) self.image_label.configure(image=image_to_display)