我遵循了senddex的教程,以获取可以在不同框架之间导航的实用tkinter GUI,虽然成功了,但我将其实现到了我的主要python bank系统,但似乎遇到了属性错误。
这是tkinter的多帧代码:
class BankSystemGUI(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, PageOne):
frame = F(container, self)
self.frames[F] = frame
frame.grid(row=0, column=0, sticky="nsew")
self.show_frame(LoginPage)
def show_frame(self, cont):
frame = self.frames[cont]
frame.tkraise()
class LoginPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
label_1 = tk.Label(self, text="Welcome to the Python Bank System", font=LARGE_FONT)
label_1.pack(pady=10, padx=10)
label_2 = tk.Label(self, text="~~~~~~~~~~~~~~~~~~~~~~~~~~~~~", font=LARGE_FONT)
label_2.pack(pady=10, padx=10)
button1 = tk.Button(self, text="Admin login", command=lambda: self.run_main_options)
button1.pack()
button2 = tk.Button(self, text="Quit Python Bank System", command=lambda: self.run_main_options)
button2.pack()
这是我运行主要管理选项的代码,我使用了一个按钮,因此当单击它时,它将在终端中显示此菜单:
def run_main_options(self):
loop = 1
while loop == 1:
choice = self.main_menu()
if choice == 1:
username = input("\n Please input admin username: ")
password = input("\n Please input admin password: ")
msg, admin_obj = self.admin_login(username, password)
print(msg)
if admin_obj != None:
self.run_admin_options(admin_obj)
elif choice == 2:
print("This option is not available yet")
elif choice == 3:
loop = 0
print("\n Thank-You for stopping by the bank!")
我莫名其妙地出现了一个 'LoginPage' object has no attribute 'run_main_options'
错误,那么我需要在任何这些代码中添加或更改才能使其正常工作吗?