Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #51072 > unrolled thread
| Started by | hsiwrek@walla.com |
|---|---|
| First post | 2013-07-22 23:52 -0700 |
| Last post | 2013-07-23 09:27 -0400 |
| Articles | 4 — 3 participants |
Back to article view | Back to comp.lang.python
tkinter progress bar hsiwrek@walla.com - 2013-07-22 23:52 -0700
Re: tkinter progress bar Christian Gollwitzer <auriocus@gmx.de> - 2013-07-23 10:43 +0200
Re: tkinter progress bar hsiwrek@walla.com - 2013-07-23 02:38 -0700
Re: tkinter progress bar Jason Swails <jason.swails@gmail.com> - 2013-07-23 09:27 -0400
| From | hsiwrek@walla.com |
|---|---|
| Date | 2013-07-22 23:52 -0700 |
| Subject | tkinter progress bar |
| Message-ID | <e1aae2d8-4e27-4644-8119-173fd8f5b47e@googlegroups.com> |
Hi, How can I add a tkinter progress bar in python 3.2 to start before a loop and end after it. I am looking for a very simple solution. def MyFunc(): Start progress bar for fileName in fileList: … End progress bar Thanks a lot in advance.
[toc] | [next] | [standalone]
| From | Christian Gollwitzer <auriocus@gmx.de> |
|---|---|
| Date | 2013-07-23 10:43 +0200 |
| Message-ID | <kslfb0$pi0$1@dont-email.me> |
| In reply to | #51072 |
Am 23.07.13 08:52, schrieb hsiwrek@walla.com: > Hi, > > How can I add a tkinter progress bar in python 3.2 to start before a loop and end after it. I am looking for a very simple solution. > > def MyFunc(): > Start progress bar > > for fileName in fileList: > … > > End progress bar > 1. There is a progress bar widget in ttk. At the beginning, you set maximum to the number of files in your list 2. In the loop, you set "value" of the progressbar to the current file number. You can also attach a variable 3. The bar is only redrawn when you process events. The simplest way to do this is by calling update() on the progress bar, which processes all pending events. Despite of it looking like a method, update() is really a global function within Tcl and updates all widgets in your interface. You must make sure, therefore, that the user does not trigger another event which interferes with your download, such as pressing the button for starting it again. The easiest way is to disable the button at the begin and reenable it at the end. 4. If processing of a single file takes a long time, the only way to have the GUI responsive is to put the work in a background thread. That seems to be more involved. Christian
[toc] | [prev] | [next] | [standalone]
| From | hsiwrek@walla.com |
|---|---|
| Date | 2013-07-23 02:38 -0700 |
| Message-ID | <fe5a2cf6-2135-4d93-947a-bf9a51a3c15c@googlegroups.com> |
| In reply to | #51075 |
Dear Christian, Thanks for the help. Can you please add a source example as I am new with Tkinter. Cheers.
[toc] | [prev] | [next] | [standalone]
| From | Jason Swails <jason.swails@gmail.com> |
|---|---|
| Date | 2013-07-23 09:27 -0400 |
| Message-ID | <mailman.5007.1374586082.3114.python-list@python.org> |
| In reply to | #51078 |
[Multipart message — attachments visible in raw view] — view raw
On Tue, Jul 23, 2013 at 5:38 AM, <hsiwrek@walla.com> wrote:
> Dear Christian,
>
> Thanks for the help. Can you please add a source example as I am new with
> Tkinter.
>
http://docs.python.org/2/library/ttk.html#progressbar
You can do something like this:
#!/usr/bin/env python
import Tkinter as tk
import ttk
import time
class MainApp(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master)
self.progress = ttk.Progressbar(self, maximum=10)
self.progress.pack(expand=1, fill=tk.BOTH)
self.progress.bind("<Button-1>", self._loop_progress)
def _loop_progress(self, *args):
for i in range(10):
self.progress.step(1)
# Necessary to update the progress bar appearance
self.update()
# Busy-wait
time.sleep(2)
if __name__ == '__main__':
root = tk.Tk()
app = MainApp(root)
app.pack(expand=1, fill=tk.BOTH)
root.mainloop()
This is a simple stand-alone app that (just) demonstrates how to use the
ttk.Progressbar widget.
HTH,
Jason
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web