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
有谁知道我做错了吗?感谢您提前提供任何帮助。
啊当然是谢谢你。你知道为什么它说'模块',而不是'tkinter',但? – guribe94
@ guribe94,不客气。因为限定符Tkinter('tk')是一个模块。尝试'输入(tk)' – falsetru