From d1400da930cc5589724f78e00c09f2c6a840a7ed Mon Sep 17 00:00:00 2001 From: Clement Desmidt Date: Wed, 24 May 2023 17:25:17 +0200 Subject: [PATCH] :bug: Make sound works with executable Fix #23 --- main.py | 5 +++++ makefile | 5 ++++- src/window/image.py | 7 +++++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 337d3e8..32f1d1e 100644 --- a/main.py +++ b/main.py @@ -1,8 +1,13 @@ +import os +import sys from tkinter import * from src.window.app import App def main(): + if getattr(sys, 'frozen', False): + os.chdir(sys._MEIPASS) + root = Tk() root.title("Drawing Training!") root.geometry("300x600") diff --git a/makefile b/makefile index dd1c8fe..2c1b4cd 100644 --- a/makefile +++ b/makefile @@ -1,2 +1,5 @@ +.PHONY: build dist + build: - pyinstaller main.py --onefile -w --hidden-import="PIL._tkinter_finder" -n drawingtraining \ No newline at end of file + rm -rf build dist drawingtraining.spec + pyinstaller main.py --onefile -w --hidden-import="PIL._tkinter_finder" -n drawingtraining --add-data "assets:assets" \ No newline at end of file diff --git a/src/window/image.py b/src/window/image.py index 56472a5..24f54e8 100644 --- a/src/window/image.py +++ b/src/window/image.py @@ -13,6 +13,8 @@ class ImageWindow: self.window = Toplevel(app.root) self.window.title("Image") self.window.geometry("1280x1024") + self.window.protocol("WM_DELETE_WINDOW", self.on_closing) + self.option = { "bw": False, "mirror": False, @@ -33,6 +35,9 @@ class ImageWindow: self.toolbar = Toolbar(self, self.timer) self.image = ImagePlaceholder(self, self.images) + def on_closing(self): + self.countdown_sound.stop() + def next_image(self): if self.toolbar.timer_check is not None: self.window.after_cancel(self.toolbar.timer_check) @@ -41,10 +46,8 @@ class ImageWindow: def lets_draw(self, images, timer): random.shuffle(images) - # self.images = images self.image.images = images self.toolbar.timer = timer - # self.timer = timer self.next_image() def play_countdown(self):