Skip to content

Commit 7541931

Browse files
committed
refactor simple_ui.py:
- Add a resource_path function - Add an icon to the window
1 parent e0e1a2e commit 7541931

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

simple_ui.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
1+
"""
2+
This module contains the main function for the application.
3+
"""
14
from tkinter import ttk
25
import tkinter as tk
36
from tkinter import messagebox
47
import threading
8+
import os
9+
import sys
510
from main import main
611

12+
def resource_path(relative_path):
13+
"""Get absolute path to resource, works for dev and for PyInstaller"""
14+
if hasattr(sys, '_MEIPASS'):
15+
return os.path.join(sys._MEIPASS, relative_path)
16+
return os.path.join(os.path.abspath("."), relative_path)
17+
718

819
class MainApplication(tk.Frame):
920
"""
@@ -41,14 +52,11 @@ def __init__(self, parent, *args, **kwargs):
4152
def button_clicked(self):
4253
"""
4354
Event handler for when the user clicks on the "Run Script" button.
44-
Disables the button and displays a "Please wait" message box while the main function runs.
55+
Disables the button, displays a "Please wait" message box, and runs the main function.
4556
"""
4657
# Disable the button to prevent multiple runs
4758
self.run_button.config(state=tk.DISABLED)
4859

49-
# Hide the root window
50-
self.parent.withdraw()
51-
5260
# Display a "Please wait" message box
5361
self.wait_message = tk.Toplevel(self.parent)
5462
self.wait_message.title("Wait")
@@ -60,6 +68,9 @@ def button_clicked(self):
6068
wait_label = ttk.Label(self.wait_message, text="Please wait...")
6169
wait_label.pack(padx=20, pady=10)
6270

71+
# Set focus on the "Please wait" window and make it modal
72+
self.wait_message.grab_set()
73+
6374
# Create a thread to run the main() function
6475
progress_thread = threading.Thread(target=self.run_main)
6576
progress_thread.start()
@@ -88,4 +99,9 @@ def run_main(self):
8899
if __name__ == '__main__':
89100
root = tk.Tk()
90101
MainApplication(root).pack(side="top", fill="both", expand=True)
102+
103+
# Set the icon for the root window
104+
icon = resource_path("clock.ico")
105+
root.iconbitmap(default=icon)
106+
91107
root.mainloop()

0 commit comments

Comments
 (0)