2012-12-09 8 views
5

tkinterでプログラムを作成しようとしています。私はプログラムを終了していませんが、私のウィンドウがどのように見えるかを見るためにそれを実行しようとすると、私はtkinterの中でエラーになります。tkinterのAttributeError

私は今何をすべきか分かりません。誰がそれが間違っているか知っている?ここで

あなたはこのようなボタンを作成する必要がありますメッセージ

Traceback (most recent call last): 
    File "<string>", line 420, in run_nodebug 
    File "<module1>", line 53, in <module> 
    File "<module1>", line 50, in main 
    File "<module1>", line 23, in __init__ 
    File "C:\Python33\lib\tkinter\__init__.py", line 2110, in __init__ 
    Widget.__init__(self, master, 'button', cnf, kw) 
    File "C:\Python33\lib\tkinter\__init__.py", line 2036, in __init__ 
    classes = [(k, v) for k, v in cnf.items() if isinstance(k, type)] 
AttributeError: 'str' object has no attribute 'items' 

import tkinter 
import tkinter.messagebox 

#---------------------- define GUI class 
class CalcMPG: 
    def __init__(self): 
     self.main_window = tkinter.Tk() 

     #-------------- create 3 frames --------- 
     self.uframe= tkinter.Frame(self.main_window) #upper frame 
     self.mframe= tkinter.Frame(self.main_window) #middle frame 
     self.bframe= tkinter.Frame(self.main_window) #button frame 

     #------------ create the 3 label widgets ------------ 
     self.lblgal= tkinter.Label(self.uframe, text="Enter # of gallons used") 
     self.lblmiles= tkinter.Label(self.mframe, text="Enter miles travelled") 

     #------------ create the 2 Entry widgets ------------ 
     self.entgal= tkinter.Entry(self.uframe, width=10) 
     self.entmiles= tkinter.Entry(self.mframe, width=10) 

     #------------ create the 2 Button widgets ----------- 
     self.mpgbtn = tkinter.Button(self.bframe, "Calcualte MPG") 
     self.extbtn = tkinter.Button(self.bframe, "Exit") 


     #-------- pack upper frame ----------- 
     self.lblgal.pack(side='left') 
     self.entgal.pack(side='right') 

     #------- pack middle frame ---------- 
     self.lblmiles.pack(side='left') 
     self.entmiles.pack(side='right') 

     #------- pack bottom frome ---------- 
     self.mpgbtn.pack(side= 'left') 
     self.extbtn.pack(side= 'right') 


     #------- pack frames -------- 
     self.uframe.pack(side='top') 
     self.mframe.pack(side='top') 
     self.bframe.pack(side='top') 


     tkinter.mainloop() 

#--------------- define main function ---- 
def main(): 
    calcmpg = CalcMPG() 

#--------- invoke main function ------- 
main() 

答えて

4

である、つまりあなたがラベルにやったように、これらの文字列値は、ボタンのテキストプロパティの値であることを明示的に指定します。

self.mpgbtn = tkinter.Button(self.bframe, text="Calculate MPG") 
self.extbtn = tkinter.Button(self.bframe, text="Exit")