I want to know how best to use the same progress (definite and indefinite). In this example, the same progress bar is used for indefinite, for deterministic and indefinite calculation of functions. When I run the code, only the last progress indicator is displayed.
from Tkinter import * import ttk import tkFileDialog import time def foo(m, n, self_from_class): for i in xrange(m): i * n self_from_class.pbar_f.step(1) self_from_class.update() time.sleep(0.1) return i class MainWindow(Frame): def __init__(self): Frame.__init__(self) self.master.title("ProgressBar example") self.master.minsize(200, 100) self.grid(sticky=E+W+N+S) top = self.winfo_toplevel() top.rowconfigure(0, weight=1) top.columnconfigure(0, weight=1) self.start = Button(self, text='Start', command=self.start, activeforeground="red") self.start.grid(row=0, column=0, pady=2, padx=2, sticky=E+W+N+S) self.pbar_ind = ttk.Progressbar(self, orient="horizontal", length=300, mode="indeterminate") self.pbar_ind.grid(row=1, column=0, pady=2, padx=2, sticky=E+W+N+S) self.pbar_det = ttk.Progressbar(self, orient="horizontal", length=300, mode="determinate") self.pbar_det.grid(row=1, column=0, pady=2, padx=2, sticky=E+W+N+S) self.pbar_f = ttk.Progressbar(self, orient="horizontal", length=300, mode="indeterminate") self.pbar_f.grid(row=1, column=0, pady=2, padx=2, sticky=E+W+N+S) def start(self): for i in xrange(10): self.pbar_ind.step(1) self.update()
UPDATE is my elegant solution:
class MainWindow(Frame): def __init__(self): Frame.__init__(self) self.master.title("ProgressBar example") self.master.minsize(200, 100) self.grid(sticky=E+W+N+S) top = self.winfo_toplevel() top.rowconfigure(0, weight=1) top.columnconfigure(0, weight=1) self.start = Button(self, text='Start', command=self.start, activeforeground="red") self.start.grid(row=0, column=0, pady=2, padx=2, sticky=E+W+N+S) self.pbar_f = ttk.Progressbar(self, orient="horizontal", length=300, mode="indeterminate") self.pbar_det = ttk.Progressbar(self, orient="horizontal", length=300, mode="determinate") self.pbar_ind = ttk.Progressbar(self, orient="horizontal", length=300, mode="indeterminate") self.pbar_ind.grid(row=1, column=0, pady=2, padx=2, sticky=E+W+N+S) def start(self): for i in xrange(10): self.pbar_ind.step(1) self.update()