From 931992cb0c01c36c113070eb5dbf8e43452e5a43 Mon Sep 17 00:00:00 2001 From: DevilXD Date: Wed, 29 Dec 2021 14:14:32 +0100 Subject: [PATCH] Fix window icon bundling with executable --- build.bat | 2 +- gui.py | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/build.bat b/build.bat index dac7f1e..f59286d 100644 --- a/build.bat +++ b/build.bat @@ -1 +1 @@ -pyinstaller -F -n "Twitch Drops Miner (by DevilXD)" -i pickaxe.ico main.py +pyinstaller -F -w -n "Twitch Drops Miner (by DevilXD)" -i pickaxe.ico --add-data pickaxe.ico;. main.py diff --git a/gui.py b/gui.py index 4527119..43bb5c6 100644 --- a/gui.py +++ b/gui.py @@ -1,5 +1,7 @@ from __future__ import annotations +import os +import sys import asyncio import logging import tkinter as tk @@ -22,6 +24,12 @@ digits = ceil(log10(WS_TOPICS_LIMIT)) WS_FONT = ("Courier New", 10) +def resource_path(relative_path): + """Get absolute path to resource, works for dev and for PyInstaller""" + base_path = getattr(sys, "_MEIPASS", os.path.dirname(os.path.abspath(__file__))) + return os.path.join(base_path, relative_path) + + class TKOutputHandler(logging.Handler): def __init__(self, output: GUIManager): super().__init__() @@ -656,7 +664,7 @@ class GUIManager: self._closed = asyncio.Event() self._root = root = Tk() root.resizable(False, True) - root.iconbitmap("pickaxe.ico") # window icon + root.iconbitmap(resource_path("pickaxe.ico")) # window icon root.title(f"Twitch Drops Miner v{__version__} (by DevilXD)") # window title root.protocol("WM_DELETE_WINDOW", self._on_close) root.bind_all("", self.unfocus)