如何从tkinter中的不同类访问变量?
我一直在搜索很多,但我仍然不知道如何从python中的不同类中访问变量。在这种情况下,我想self.v
从PageOne
类到PageTwo
类访问变量。
这是我的代码。
import tkinter as tkimport smtplib TITLE_FONT = ("Helvetica", 18, "bold")class SampleApp(tk.Tk): def __init__(self): tk.Tk.__init__(self) 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 (StartPage, PageOne, PageTwo): frame = F(container, self) self.frames[F] = frame frame.grid(row=0, column=0, sticky="nsew") self.show_frame(StartPage) def show_frame(self, c): frame = self.frames[c] frame.tkraise()class StartPage(tk.Frame): def __init__(self, parent, controller): tk.Frame.__init__(self, parent) label = tk.Label(self, text="PyMail",foreground = "Red", font=("Courier", 30, "bold")) label.pack(side="top") sublabel = tk.Label(self, text="Bringing you the\n the easiest way of communication", font=("Courier", 15)) sublabel.pack() wallpaper = tk.PhotoImage(file='Python-logo-notext.gif') img = tk.Label(self, image=wallpaper) img.image = wallpaper img.pack(side="top", expand = True) button1 = tk.Button(self, text="Click Here to Login to your account",fg="red", command=lambda: controller.show_frame(PageOne)) button2 = tk.Button(self, text="Go to Page Two", command=lambda: controller.show_frame(PageTwo)) button2.pack(side="bottom") button1.pack(side="bottom")class PageOne(tk.Frame):
Helenr
相关分类