【发布时间】:2018-07-16 07:02:07
【问题描述】:
我正在尝试访问在类内部以及嵌套函数内部的变量。我正在尝试将该变量访问到另一个类中,但是在使用 'global' 之后我没有运气访问它。谁能帮忙
这是代码
class SampleApp(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
#Some code
def show_frame(self, page_name):
#Some code
class StartPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
#Some code
class PageOne(tk.Frame):
def __init__(self, parent, controller):
def click():
entered_text=textentry.get()
#Some code
class PageTwo(StartPage,PageOne):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
#Some code
if __name__ == "__main__":
app = SampleApp()
app.mainloop()
我正在尝试将存在于PageOne 类中的entered_text 访问到__init__ 方法中的PageTwo 类中
问候 萨加尔
【问题讨论】:
-
你能做一个最小的、完整的、可验证的例子吗? stackoverflow.com/help/mcve
-
例如用户
pass而不是#some code并在没有不必要的 tk 参考的情况下制作最小示例。
标签: python global-variables local-variables class-variables nested-function