I am getting:
print (p.s) AttributeError: StartPage instance has no attribute 's'
here is my code:
import Tkinter as tk
class SampleApp(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
self.s = []
self.rowconfigure(0, weight=1)
self.columnconfigure(0, weight=1)
container = tk.Frame(self)
container.grid(row=0, column=0, sticky='we')
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)
self.frames = {}
for F in (StartPage, images_result):
page_name = F.__name__
frame = F(parent=container, controller=self)
frame.grid(row=0, column=0, sticky='nsew')
self.frames[page_name] = frame
self.show_frame("StartPage")
def get_SP(self):
return self.frames["StartPage"]
def images(self, page_name):
self.s = [1, 2]
frame = self.frames[page_name]
frame.tkraise()
def show_frame(self, page_name):
'''Show a frame for the given page name'''
frame = self.frames[page_name]
frame.grid(row=0, column=0, sticky='snew')
frame.tkraise()
class StartPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
self.image_btn = tk.Button(self, text="Images", command=lambda: controller.images("images_result"))
self.image_btn.grid(row=0, column=0, sticky='snew')
class images_result(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
p = self.controller.get_SP()
print (p.s)
app = SampleApp()
app.mainloop()
Edited:
I want the function images in SampleApp to update the attribute s of the SampleApp then I want to be able to access it from the class images_results.
I tried to use
print(self.controller.s)
but that gives me [] and by that it seems that the modification that has been done by the function images to the s attribute are not visible to the images_result.