Kac*_*aso 2 python model-view-controller tkinter
所以我有以下,完美的工作:
import tkinter as tk
class App(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 (LoginPage, ProjPage):
frame = F(container, self)
self.frames[F] = frame
frame.grid(row=0, column=0, rowspan=12, columnspan=6, sticky="nsew")
self.show_frame(LoginPage)
def show_frame(self, c):
frame = self.frames[c]
frame.tkraise()
class LoginPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
Btn = tk.Button(self, text="Sign In", command=lambda: controller.show_frame(ProjPage))
Run Code Online (Sandbox Code Playgroud)
但我希望最后一个按钮命令位于一个单独的函数中,所以我可以先做一些评估:
Btn = tk.Button(self, text="Sign In", command=self.signIn)
def signIn(self):
# do some stuff here
self.controller.show_frame(ProjPage)
Run Code Online (Sandbox Code Playgroud)
这不起作用; 无论我是否尝试通过控制器,或使用lambda,似乎没有任何工作>.<我没有得到什么?
你似乎并不初始化controller在self.把它放在那里__init__的LoginPage,就像这样:
self.controller = controller
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3457 次 |
| 最近记录: |