Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think the problem is that the time-consuming loop is preventing the <code>tkinter</code> event loop, <a href="http://effbot.org/tkinterbook/widget.htm#Tkinter.Widget.mainloop-method" rel="nofollow noreferrer"><code>mainloop()</code></a>, from running. In other words, when your work intensive function runs in the same thread as the GUI, it interferes with it by hogging the interpreter. </p> <p>To prevent this you can use a secondary <a href="http://docs.python.org/2/library/threading.html?highlight=thread#threading.Thread" rel="nofollow noreferrer">Thread</a> to run your function and run the GUI and its progressbar in the main thread. To give you and idea of how to do this, here's a simple example I derived from code in a another (unrelated) <a href="https://stackoverflow.com/questions/6212896/python-ttk-progressbar">progressbar question</a> to show how easily something like that can be done. <em>Note:</em> It's generally recommended that secondary threads not be given direct access to the main thread's <code>tkinter</code> objects.</p> <pre><code>from Tkinter import * import ttk import time import threading def foo(): time.sleep(5) # simulate some work def start_foo_thread(event): global foo_thread foo_thread = threading.Thread(target=foo) foo_thread.daemon = True progressbar.start() foo_thread.start() root.after(20, check_foo_thread) def check_foo_thread(): if foo_thread.is_alive(): root.after(20, check_foo_thread) else: progressbar.stop() root = Tk() mainframe = ttk.Frame(root, padding="3 3 12 12") mainframe.grid(column=0, row=0, sticky=(N, W, E, S)) mainframe.columnconfigure(0, weight=1) mainframe.rowconfigure(0, weight=1) progressbar = ttk.Progressbar(mainframe, mode='indeterminate') progressbar.grid(column=1, row=100, sticky=W) ttk.Button(mainframe, text="Check", command=lambda:start_foo_thread(None)).grid(column=1, row=200, sticky=E) for child in mainframe.winfo_children(): child.grid_configure(padx=5, pady=5) root.bind('&lt;Return&gt;', start_foo_thread) root.mainloop() </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload