So, I need to access the
self.savedpasswordsinstance, but over in the CreatePassword(self) component.
Ok, I don‘t know of I got that correctly, but I think what you want is just a way to have a reference to an object of another type. In Python, objects are usually treated as references, so you can have an object “stored” at two locations at the same time.
So if you need to access the savedpasswords from a CreatePassword object, I’d recommend just storing that savedpasswords inside createpassword like this:
class App(tk.Tk):
def __init__(self):
# your previous code..
self.savedpasswords = SavedPasswords(self)
self.createpassword = CreatePassword(self)
# save savedpasswords in createpassword
self.createpassword.saved_pw_ref = self.savedpasswords
Then, inside CreatePassword, you can access that reference:
class CreatePassword:
# some method that needs access to savedpasswords
def some_method(self):
self.saved_pw_ref.do_something()
self.saved_pw_ref.do_something_else()
# …
If you don’t like setting attributes from outside, you can also create a method to save the reference:
class CreatePassword:
def set_saved_pw_ref(self, ref):
self.saved_pw_ref = ref
and then inside App you can call
self.createpassword.set_saved_pw_ref(self.savedpasswords)
Or you can also pass savedpasswords to the constructor of CreatePassword and then store it, etc..
I think for your code this is the easiest solution, however there might be other options if you refactor the code, it also depends on what savedpasswords and createpassword need to do at the end of the day, but this solution should work for you.
Please tell me if you have any questions or if I understood something wrong.