0
我正在使用tkinter並試圖創建一個框架庫,而不是讓我的程序每次都打開新的窗口。我已經開始創建一個歡迎頁面,並且我正在嘗試顯示我創建的內容,僅爲它提供了此錯誤消息。 「ValueError異常:詞典更新序列元素#0具有長度1; 2是必需的」 這是我的代碼:3 ValueError:字典更新序列元素#0的長度爲3; 2是必需的1
#!/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):
字典ELE在我的WelcomePage類中只有1個參數,但我需要兩個。我試着把self
作爲第二個參數,但沒有奏效。這在Python 3.4中工作,但現在我使用Python 3.5,它給了我這個錯誤。我將如何解決這個問題?