Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 update a variable in parent window after closing its toplevel window
#1
i want to update my variable in parent window when i close its toplevel window.
i cretaed a function "new_window"...this function creates a new window(Demo2 class) ...demo2 is a sample of Demo2 class...the "demo2.destroyed" is a variable for understanding whether the toplevel window was closed or not....
i recieved this error " 'int' object is not iterable"
why????
please help

my code is:
def new_window(self):
        
        demo2 = Demo2(self.master, self.var_sent)
        
        def check_demo2():
            if demo2.destroyed:
                
                global fasele
                global counter
                counter += fasele
        
                self.tyLabel.config(text=str(counter))
                
            else:
                self.master.after(100, check_demo2)

        check_demo2()]
Moderator:
added opening python code tag :-)
Quote
#2
You could also consider to use the module 'Publisher'. Prepare a publisher in the toplevel window that sends a message in case of being destroyed (or a publisher at the same point where you give the command to destroy, if this is elsewhere) and a listener in your demo2. This will 'eavesdrop' continually.
Quote
#3
(Mar-12-2017, 05:10 PM)merlem Wrote: You could also consider to use the module 'Publisher'. Prepare a publisher in the toplevel window that sends a message in case of being destroyed (or a publisher at the same point where you give the command to destroy, if this is elsewhere) and a listener in your demo2. This will 'eavesdrop' continually.

this program understand when the toplevel window is closed...but the parent window (that is a class) can not update the value of the variable that gets from the toplevel window
Quote
#4
I'm not sure whether I really understand this problem.
However, if the publisher is not a solution, it would be helpful to know in which line of your code the error occurs. I can't assing that until now.
Quote
#5
If the window has a parent, then it isn't the toplevel window.
Quote
#6
Quote:If the window has a parent, then it isn't the toplevel window

This is true logically, but tkinter has a Toplevel window which can have a parent

Toplevel(master=None, **options)
(class) [#]
example
>>> zz = tk.Tk()
>>> f1 = tk.Frame(zz)
>>> t1 = tk.Toplevel(f1)
>>> zz.mainloop()
So here, the frame f1 is the parent of Toplevel t1
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  [PyQt] how to dynamically add label to pyqt window Joongi 3 241 Sep-10-2019, 01:38 PM
Last Post: Denni
  [Tkinter] Extrakt a Variable from a closed tkinter window hWp 5 228 Aug-23-2019, 09:01 PM
Last Post: woooee
  Extra annoying window mcmxl22 1 232 Jul-03-2019, 05:22 PM
Last Post: ichabod801
  Require scroll bars horizontal and vertical throughout the window tejgandhi 2 276 Jun-28-2019, 03:13 AM
Last Post: tejgandhi
  Removing window borders DT2000 1 220 Jun-27-2019, 04:10 AM
Last Post: DT2000
  [split] Closing a window but not the whole program scriptdrache 1 179 Jun-25-2019, 03:43 PM
Last Post: joe_momma
  [Tkinter] Text window not properly sized smabubakkar 1 248 Jun-16-2019, 08:55 AM
Last Post: Yoriz
  [PyQt] Window resizing help FesterJester 2 566 Jun-10-2019, 01:59 PM
Last Post: Denni
  [Tkinter] Tkinter window pop up again when i click button Orimura_Sandy 1 402 May-12-2019, 08:17 PM
Last Post: joe_momma
  [Tkinter] How do I stop window changing size? microphone_head 1 251 May-02-2019, 11:34 AM
Last Post: microphone_head

Forum Jump:


Users browsing this thread: 1 Guest(s)