Python Forum
update a variable in parent window after closing its toplevel window
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 :-)
Reply
#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.
Reply
#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
Reply
#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.
Reply
#5
If the window has a parent, then it isn't the toplevel window.
Reply
#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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyGUI] How to reuse a window layout based on mysql rowcount? retroisbest 2 224 Nov-09-2021, 09:02 AM
Last Post: retroisbest
  [Tkinter] Tkinter Window Has no Title Bar gw1500se 4 315 Nov-07-2021, 05:14 PM
Last Post: gw1500se
  [Tkinter] Update variable using tkinter entry methon drSlump 6 643 Oct-15-2021, 08:01 AM
Last Post: drSlump
  [Tkinter] Tk window not displaying until loop has completed Ganga 8 1,818 Aug-09-2021, 06:42 PM
Last Post: Ganga
  [Tkinter] window full screen w/ taskbar at top... 3python 0 395 Aug-04-2021, 09:06 PM
Last Post: 3python
  [PyQt] Can't get MDIarea to resize automatically with Main Window JayCee 4 614 Aug-02-2021, 08:47 PM
Last Post: JayCee
  [Tkinter] [split] [split] How to make a window stay on top knoxvilles_joker 10 2,801 May-22-2021, 03:54 AM
Last Post: knoxvilles_joker
  [PyQt] My WIndow isnt opening at all. SovietMilkerGenerak 1 1,072 Apr-24-2021, 12:25 PM
Last Post: Yoriz
  update text variable on label with keypress knoxvilles_joker 3 1,361 Apr-17-2021, 11:21 PM
Last Post: knoxvilles_joker
  [PyQt] How to clip layout to sides and bottom of main window? Valmont 9 1,668 Mar-24-2021, 10:00 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020