我正在使用tkinter并尝试创建一个框架库,而不是让我的程序每次都打开新窗口。我已经开始创建一个欢迎页面,我正在尝试显示我创建的内容,只为它提供此错误消息。”值错误:字典更新序列元素0的长度为1;需要2“ 这是我的代码:
#!/usr/bin/python
from tkinter import *
import tkinter as tk
Large_Font = ("Verdana", 18)
class ATM(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 i in (WelcomePage, Checking):
frame = i(container, self)
self.frames[i] = frame
frame.grid(row= 0, column = 0, sticky= "nsew")
self.show_frame(WelcomePage)
def show_frame(self, cont):
frame = self.frames[cont]
frame.tkraise()
class WelcomePage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
label = tk.Label(self, "Welcome to the ATM Simulator", font = Large_Font)
label.pack(pady=100, padx=100)
checkButton = Button(self, text = "Checking Account",
command = lambda: controller.show_frame(Checking))
checkButton.pack()
class Checking(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent, controller)
self.controller = controller
label = tk.Label(self, "Welcome to the ATM Simulator", font = Large_Font)
label.pack(pady=100, padx=100)
homeButton = Button(self, text = "Back to Home Page",
command = lambda: controller.show_frame(WelcomePage))
homeButton.pack()
app = ATM()
app.mainloop()
出现错误消息是因为我声明
frame = i(container, self)
但当我创建第一类时
class WelcomePage(tk.Frame):
WelcomePage类中的dictionary元素只有1个参数,但我需要两个参数。我试着把self
作为第二个参数,但是没有用。这在Python3.4中起作用,但是现在我使用的是Python3.5,它给我带来了这个错误。我该怎么解决这个问题?在
我不认为
^{pr2}$Frame
的初始值设定项可以接受这么多参数,除非controller
是字典。尝试:您还应该使用
text
命名参数来指定标签的文本。在相关问题 更多 >
编程相关推荐