Note that there are some explanatory texts on larger screens.

plurals
  1. POPython: How to get progressbar start() info from one window (class) to other
    primarykey
    data
    text
    <p>There is a main window with menu and the progressbar. A correspondence window with OK button opens upon menu command and the OK button starts the process (here: 3 sec. sleep). The correspondence window is created via inheritance from a class I have not provided here (If required for answer, please let me know). The methods <code>apply</code> and <code>ok</code> override existing methods in the mother class.</p> <p>Now my problem: Since the progressbar sits in the main window (class App) and <code>progressbar(start)</code> and <code>progressbar(stop)</code> in the correspondence window I somehow have to pass (start) and (stop) via the mother class tkSimpleDialog.Dialog to class App. So I thought I also override the <code>__init__(self..)</code> method, provide <code>self.</code> to progressbar.</p> <p>How can I make this work?</p> <pre><code>import Tkinter, ttk, tkFileDialog, tkSimpleDialog, time, threading class App: def __init__(self, master, progressbar): self.progress_line(master) def progress_line (self, master): self.progressbar = ttk.Progressbar(master, mode='indeterminate') self.progressbar.place(anchor = 'ne', height = "20", width = "150", x = "175", y = "30") class AppMenu(object): def __init__(self, master, progressbar): self.master = master self.menu_bar() def menu_bar(self): menu_bar = Tkinter.Menu(self.master) self.menu_bar = Tkinter.Menu(self.master) self.master.config(menu=self.menu_bar) self.create_menu = Tkinter.Menu(self.menu_bar, tearoff = False) self.create_menu.add_command(label = "do", command = self.do) self.menu_bar.add_cascade(label = "now", menu = self.create_menu) def do(self): do1 = Dialog(self.master, progressbar) class Dialog(tkSimpleDialog.Dialog): def __init__(self, parent, progressbar): tkSimpleDialog.Dialog.__init__(self, parent, progressbar) self.transient(parent) self.parent = parent self.result = None self.progressbar = progressbar body = Frame(self) self.initial_focus = self.body(body) body.pack(padx=5, pady=5) self.buttonbox() self.grab_set() if not self.initial_focus: self.initial_focus = self self.protocol("WM_DELETE_WINDOW", self.cancel) self.geometry("+%d+%d" % (parent.winfo_rootx()+50, parent.winfo_rooty()+50)) self.initial_focus.focus_set() self.wait_window(self) def ok(self, event=None): self.withdraw() self.start_foo_thread() self.cancel() def apply(self): time.sleep(5) def start_foo_thread(self): global foo_thread self.foo_thread = threading.Thread(target=self.apply) self.foo_thread.daemon = True self.progressbar.start() self.foo_thread.start() master.after(20, check_foo_thread) def check_foo_thread(self): if self.foo_thread.is_alive(): root.after(20, self.check_foo_thread) else: self.progressbar.stop() master = Tkinter.Tk() progressbar = None app = App(master, progressbar) appmenu = AppMenu(master, progressbar) master.mainloop() </code></pre> <p>error messages: first after clicking ok:</p> <pre><code>Exception in Tkinter callback Traceback (most recent call last): File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 1410, in __call__ File "ask-progressbar.py", line 57, in ok self.start_foo_thread() File "ask-progressbar.py", line 66, in start_foo_thread self.progressbar.start() AttributeError: Dialog2 instance has no attribute 'progressbar' </code></pre> <p>second: after closing app</p> <pre><code>Exception in Tkinter callback Traceback (most recent call last): File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 1410, in __call__ File "ask-progressbar.py", line 26, in do do1 = Dialog2(self.master, progressbar) File "ask-progressbar.py", line 33, in __init__ self.transient(parent) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 1652, in wm_transient TclError: can't invoke "wm" command: application has been destroyed </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    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