python 3.5 pass object from one class to another <p>I am trying to figure out how to pass data from one class into another. My knowledge of python is very limited and the code I am using has been taken from examples on this site. </p> <p>I am trying to pass the User name from "UserNamePage" class into "WelcomePage" class. Can someone please show me how to achieve this. I will be adding more pages and I will need to pass data between the different pages</p> <p>Below is the full code - as mentioned above most of this code has come from other examples and I am using these examples to learn from. </p> <pre><code>import tkinter as tk from tkinter import * from tkinter import ttk from tkinter import messagebox import datetime import re def Chk_String(mystring): Allowed_Chars = re.compile('[a-zA-Z_-]+$') return Allowed_Chars.match(mystring) def FnChkLogin(Page): booAllFieldsCorrect = False; myFName = Page.FName.get() myFName = myFName.replace(" ", "") myLName = Page.LName.get() myLName = myLName.replace(" ", "") if myFName == "": messagebox.showinfo('Login Ifo is Missing', "Please type in your First Name") elif not Chk_String(myFName): messagebox.showinfo('First Name Error:', "Please only use Leter or - or _") elif myLName == "": messagebox.showinfo('Login Info is Missing', "Please type in your Last Name") elif not Chk_String(myLName): messagebox.showinfo('Last Name Error:', "Please only use Leter or - or _") else: booAllFieldsCorrect = True; if booAllFieldsCorrect == True: app.geometry("400x200") app.title("Welcome Screen") PageController.show_frame(app,"WelcomePage") def FnAddButton(Page,Name,Label,Width,X,Y,FnAction): Name = ttk.Button (Page, text=Label,width=int(Width),command=FnAction) Name.place(x=int(X),y=int(Y)) class PageController(tk.Tk): def __init__(self, *args, **kwargs): tk.Tk.__init__(self, *args, **kwargs) container = tk.Frame(self) container.pack(side="top",fill="both",expand="True") container.grid_rowconfigure(0,weight=1) container.grid_columnconfigure(0,weight=1) self.frames={} for F in (UserNamePage,WelcomePage): page_name = F.__name__ frame = F(container,self) self.frames[page_name] = frame frame.grid(row=0,column=0,sticky="nsew") self.show_frame("UserNamePage") def show_frame(self,page_name): frame= self.frames[page_name] frame.tkraise() class UserNamePage(tk.Frame): def __init__(self,parent,controller): tk.Frame.__init__(self,parent) self.controller = controller lblFName = Label(self,text="First Name ",relief=GROOVE,width=12,anchor=E).place(x=50,y=50) lblLName = Label(self,text="Last Name ",relief=GROOVE,width=12,anchor=E).place(x=50,y=75) self.FName = StringVar() inputFName = Entry(self,textvariable=self.FName,width=25).place(x=142,y=50) self.LName = StringVar() inputLName = Entry(self,textvariable=self.LName,width=25).place(x=142,y=75) cmdContinue = ttk.Button (self, text='Continue',width=9,command=lambda:FnChkLogin(self)).place(x=320,y=70) class WelcomePage(tk.Frame): def __init__(self,parent,controller): tk.Frame.__init__(self,parent) self.controller = controller UserNamePageData = UserNamePage(parent,controller) UserFName = str(UserNamePageData.FName) UserLName = str(UserNamePageData.LName) strWelcome = "Welcome " + UserFName + " " + UserLName lblWelcome = Label(self,text=strWelcome,relief=FLAT,width=50,anchor=W).place(x=25,y=25) if __name__ == "__main__": app = PageController() app.geometry("400x200") app.title("User Page") app.eval('tk::PlaceWindow %s center' % app.winfo_pathname(app.winfo_id())) app.mainloop() </code></pre>