Reputation: 5126
I've been creating a program for myself and my company recently wants to use it. However the end-users have no python experience so I'm making a GUI for them using EasyGUI. All they have to do is click a shortcut on their desktop (I'm using pythonw.exe so no box shows up). The Process takes roughly 10 seconds to run but there is a blank screen when doing so.
My question is: Can i have a message box that says "Running..." while the function runs and then close when the entire process completes?
Bonus points: to have a progress bar while process runs.
Now I've done some searching but some of this stuff is over my head (I'm fairly new to Python). I'm not sure how to incorporate these parts into my code. Is there anything that is easy like EasyGUI to solve my problem? Thanks!
Related posts: Python- Displaying a message box that can be closed in the code (no user intervention)
How to pop up a message while processing - python
Python to print out status bar and percentage
If you absolutely need to see my code i can try and re-create it without giving away information. The higher-ups would appreciate me not giving away information about this project - Security is tight here.
Upvotes: 0
Views: 5257
Reputation: 1052
I've written a little demo for you. Don't know if it's exactly what you wanted... The code uses threading to update the progressbar while doing other stuff.
import time
import threading
try:
import Tkinter as tkinter
import ttk
except ImportError:
import tkinter
from tkinter import ttk
class GUI(object):
def __init__(self):
self.root = tkinter.Tk()
self.progbar = ttk.Progressbar(self.root)
self.progbar.config(maximum=10, mode='determinate')
self.progbar.pack()
self.i = 0
self.b_start = ttk.Button(self.root, text='Start')
self.b_start['command'] = self.start_thread
self.b_start.pack()
def start_thread(self):
self.b_start['state'] = 'disable'
self.work_thread = threading.Thread(target=work)
self.work_thread.start()
self.root.after(50, self.check_thread)
self.root.after(50, self.update)
def check_thread(self):
if self.work_thread.is_alive():
self.root.after(50, self.check_thread)
else:
self.root.destroy()
def update(self):
#Updates the progressbar
self.progbar["value"] = self.i
if self.work_thread.is_alive():
self.root.after(50, self.update)#method is called all 50ms
gui = GUI()
def work():
#Do your work :D
for i in range(11):
gui.i = i
time.sleep(0.1)
gui.root.mainloop()
Let me know if that helps :)
Upvotes: 2