#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2017
    Posts
    22
    Rep Power
    0

    Arrow update a variable in parent window after closing its toplevel window


    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:
    Code:
    [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()]
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2009
    Posts
    652
    Rep Power
    39
    i recieved this error " 'int' object is not iterable"
    why????
    Not enough info. Include the complete error message. The odds are good that the error is not even in the code you posted.

    I assume all code is in one class because of the use of self. So use self.demo2 and declare it as none at the beginning so you have a variable even if it no window has been opened yet. You can then test for self.demo2.
    Code:
    def __init__(self):
        self.demo2=None
    
    def new_window(self):
        self.demo2 = Demo2(self.master, self.var_sent)
    
    def check_demo2():
        if not self.demo2:
    And Why Are You Using Globals In A Class??? But instead of checking if the Toplevel is active, why not do whatever it is when the button is pressed to destroy it?
    Last edited by dwblas; March 12th, 2017 at 02:06 PM.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2017
    Posts
    22
    Rep Power
    0

    Arrow


    Originally Posted by dwblas
    Not enough info. Include the complete error message. The odds are good that the error is not even in the code you posted.

    I assume all code is in one class because of the use of self. So use self.demo2 and declare it as none at the beginning so you have a variable even if it no window has been opened yet. You can then test for self.demo2.
    Code:
    def __init__(self):
        self.demo2=None
    
    def new_window(self):
        self.demo2 = Demo2(self.master, self.var_sent)
    
    def check_demo2():
        if not self.demo2:
    And Why Are You Using Globals In A Class??? But instead of checking if the Toplevel is active, why not do whatever it is when the button is pressed to destroy it?
    what's the meaning of the "if not self.demo2" ?
    i use from "global", because these variables are from another class
    i used a button for closing the toplevel as you say
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2009
    Posts
    652
    Rep Power
    39
    i use from "global", because these variables are from another class
    This is not a good way to do this. You can use instance variables or class variables but there is not enough info here to decide, and that is not part of the question that created this thread so we can leave that as it is.
  8. #5
  9. Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Aug 2011
    Posts
    5,803
    Rep Power
    508
    None tests as False, as does 0 and do empty containers.
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo