0

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.

Community
  • 1
  • 1
MattR
  • 4,887
  • 9
  • 40
  • 67

1 Answers1

2

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 :)

Peter234
  • 1,052
  • 7
  • 24
  • Wow! Thanks for this. This is a little over my head haha. I can't seem to get it to run with the bar popping up, though :( Is there any documentation on tkinter or ttk or even progressbar? I can't find any documentation on what functions are in the modules, and if i do - they aren't very helpful. I'm noticing in Python that it's almost like a different language for each module haha. @Peter234, I really appreciate this. – MattR Aug 19 '16 at 14:22
  • @MattR: This Script is for Python 3 it won't run with Python 2.7 maybe this is the problem. For information about tkinter look here: https://docs.python.org/3/library/tkinter.html?highlight=tkinter#module-tkinter – Peter234 Aug 19 '16 at 16:47
  • @MattR: I've changed the code a little. Now it works on Python 2.7 and Python 3 :) – Peter234 Aug 20 '16 at 22:24