1
+ """
2
+ This module contains the main function for the application.
3
+ """
1
4
from tkinter import ttk
2
5
import tkinter as tk
3
6
from tkinter import messagebox
4
7
import threading
8
+ import os
9
+ import sys
5
10
from main import main
6
11
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
+
7
18
8
19
class MainApplication (tk .Frame ):
9
20
"""
@@ -41,14 +52,11 @@ def __init__(self, parent, *args, **kwargs):
41
52
def button_clicked (self ):
42
53
"""
43
54
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.
45
56
"""
46
57
# Disable the button to prevent multiple runs
47
58
self .run_button .config (state = tk .DISABLED )
48
59
49
- # Hide the root window
50
- self .parent .withdraw ()
51
-
52
60
# Display a "Please wait" message box
53
61
self .wait_message = tk .Toplevel (self .parent )
54
62
self .wait_message .title ("Wait" )
@@ -60,6 +68,9 @@ def button_clicked(self):
60
68
wait_label = ttk .Label (self .wait_message , text = "Please wait..." )
61
69
wait_label .pack (padx = 20 , pady = 10 )
62
70
71
+ # Set focus on the "Please wait" window and make it modal
72
+ self .wait_message .grab_set ()
73
+
63
74
# Create a thread to run the main() function
64
75
progress_thread = threading .Thread (target = self .run_main )
65
76
progress_thread .start ()
@@ -88,4 +99,9 @@ def run_main(self):
88
99
if __name__ == '__main__' :
89
100
root = tk .Tk ()
90
101
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
+
91
107
root .mainloop ()
0 commit comments