Improved GUI Responsiveness & Script Execution in Tkinter Interface#30
Improved GUI Responsiveness & Script Execution in Tkinter Interface#30abhigyaabs2 wants to merge 1 commit into
Conversation
|
@abhigyaabs2 also do mention what issue this pr solves |
|
@thynash GUI Freezing During Script Execution Previously, the GUI would freeze while executing external Python scripts (e.g., face detection, blink detection, lane detection) because subprocess.call() was blocking the main thread. •Fix: Introduced multithreading using the threading module to execute subprocesses without blocking the GUI. Python Environment Compatibility Hardcoded "python" could fail in systems with multiple Python versions or virtual environments. •Fix: Replaced with sys.executable to ensure subprocesses run with the same interpreter as the GUI app. Unstructured and Inconsistent Layout The original grid layout lacked consistent spacing and alignment. •Fix: Switched to pack() with strategic padding (pady) for a cleaner and centered button layout. Readability and Maintainability Repeated subprocess logic was hardcoded in each button function. • Fix: Introduced a single run_script(script_name) method for better code reuse and readability. |
|
👋 Hi @thynash, It resolves the GUI freezing issue and improves layout + maintainability. If there’s anything you'd like me to tweak or split into smaller commits, I’m happy to do that! 🙌 Looking forward to your feedback. |
|
Thanks @abhigyaabs2 for working on this issue.
|
|
@Gagandeep-2003 I have resolved the issue, if there is anything else then please let me know. |
@thynash
@Gagandeep-2003
Fixes: #26
Use sys.executable Instead of "python"
This ensures that subprocess runs in the same environment (especially useful when using virtual environments or Python 3+).
import sys
subprocess.call([sys.executable, "face-try.py"])
Prevent GUI Freeze with threading
Currently, when running subprocess.call(...), it blocks the GUI until the subprocess ends. To keep the GUI responsive, run each script in a separate thread.
from threading import Thread
def run_script(script_name):
def target():
subprocess.call([sys.executable, script_name])
Thread(target=target).start()
def face():
run_script("face-try.py")
def blink():
run_script("blinkDetect.py")
def lane():
run_script("lanedetection.py")
The current layout is functional but not visually centered. Using .grid(..., sticky='ew') or switching to pack() with better padding for cleaner UI.