2015-12-26 39 views
2

我試圖讓一些使用tkinter工作的單選按鈕的基本GUI,但是我在創建單選按鈕時遇到了一些麻煩。使用Tkinter的RadioButton錯誤

import Tkinter as tk # python 
... 
def createView(self): 
     label = tk.Label(self, text="Choose mode analysis", font=TITLE_FONT) 
     label.pack(side="top", fill="x", pady=10) 

     form_analysis = tk.BooleanVar() 

     # form_analysis_radioButton = tk.RadioButton(self, text="Form Analysis") 
            # variable=form_analysis, value=True) 
     # match_analysis_radioButton = tk.RadioButton(self, text="Match Analysis", 
     #            variable=form_analysis, 
     #            value=False) 
     # form_analysis_radioButton.pack() 
     # match_analysis_radioButton.pack() 

會拋出這個錯誤 文件「gui_test.py」,行72,在CreateView的

form_analysis_radioButton = tk.RadioButton(self, text="Form Analysis") 
AttributeError: 'module' object has no attribute 'RadioButton' 

這似乎在告訴我,有Tk模塊中沒有單選按鈕的功能(不知道爲什麼它說的不是「Tkinter的」模塊'雖然),所以我在命令行檢查,並得到這個

In [2]: import Tkinter as tk 

In [3]: tk.RadioButton() 
--------------------------------------------------------------------------- 
AttributeError       Traceback (most recent call last) 
<ipython-input-3-1404e954a1fa> in <module>() 
----> 1 tk.RadioButton() 

AttributeError: 'module' object has no attribute 'RadioButton' 

In [4]: from Tkinter import * 

In [5]: RadioButton() 
--------------------------------------------------------------------------- 
NameError         Traceback (most recent call last) 
<ipython-input-5-0d02b97652df> in <module>() 
----> 1 RadioButton() 

NameError: name 'RadioButton' is not defined 

有誰知道我做錯了嗎?感謝您提前提供任何幫助。

回答

2

這是一個簡單的錯字:RadioButton應替換爲Radiobutton

+0

啊當然是謝謝你。你知道爲什麼它說'模塊',而不是'tkinter',但? – guribe94

+0

@ guribe94,不客氣。因爲限定符Tkinter('tk')是一個模塊。嘗試'輸入(tk)' – falsetru