2015-11-16 49 views
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,它給了我這個錯誤。我將如何解決這個問題?

回答

2
class Checking(tk.Frame): 
    def __init__(self, parent, controller): 
     tk.Frame.__init__(self, parent, controller) 

我不認爲Frame的初始化可以接受許多爭論,除非controller是一本字典。嘗試:

class Checking(tk.Frame): 
    def __init__(self, parent, controller): 
     tk.Frame.__init__(self, parent) 

你也應該使用text命名參數指定爲標籤的文本。

label = tk.Label(self, text="Welcome to the ATM Simulator", font = Large_Font) 
相關問題