2014-09-27 58 views
-1

好的,所以我遇到了問題。我正在嘗試製作一個GUI十六進制轉換器,並且保持相同的錯誤。我不是那種經驗豐富的人,所以有人能幫助我嗎?這裏是代碼:在標籤上使用.config()時出現python錯誤

from Tkinter import * 

def getNum(): 
    hex1 = e1.get() 
    dec1 = int(hex1, 16) 
    ol.configure(text=dec1) 



root = Tk() 

introLabel = Label(root, text='Input Hex Code: ').pack() 

e1 = Entry(root) 
e1.pack() 
e1.focus_set() 

inputButton = Button(root, text='Submit Hex Code', command=getNum).pack() 

ol = Label(root, text='Hex Code will appear here.').pack() 



root.mainloop() 

,我不斷收到此錯誤:

Exception in Tkinter callback 
Traceback (most recent call last): 
File "C:\Python27\lib\lib-tk\Tkinter.py", line 1470, in __call__ 
return self.func(*args) 
File "C:/Users/The Lodges/Desktop/Python/test.py", line 6, in getNum 
ol.configure(text=dec1) 
AttributeError: 'NoneType' object has no attribute 'configure' 

回答

3

.pack()的返回值是不小部件,但None。從這個

更改代碼:

ol = Label(root, text='Hex Code will appear here.').pack() 

要這樣:

ol = Label(root, text='Hex Code will appear here.') 
ol.pack() 

這將讓ol '指點' 的標籤。

相關問題