gur*_*e94 2 python user-interface tkinter radio-button
我正在尝试使用 tkinter 获得一个带有一些单选按钮的基本 GUI,但是我在创建单选按钮时遇到了一些问题。
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()
Run Code Online (Sandbox Code Playgroud)
抛出此错误文件“gui_test.py”,第 72 行,在 createView 中
form_analysis_radioButton = tk.RadioButton(self, text="Form Analysis")
AttributeError: 'module' object has no attribute 'RadioButton'
Run Code Online (Sandbox Code Playgroud)
这似乎告诉我 tk 模块中没有 RadioButton 函数(虽然不知道为什么它说“module”而不是“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
Run Code Online (Sandbox Code Playgroud)
有谁知道我做错了什么?感谢您提前提供的任何帮助。