Skip to main content
 首页 » 编程设计

python之无法识别 Tkinter 单选按钮指示器

2025年05月04日15mfrbuaa

我希望我的单选按钮使用本页提到的按钮框界面,方法是设置 indicatoron=0:

http://effbot.org/tkinterbook/radiobutton.htm

代码片段:

import ttk  
 
... 
 
    self.selectedSectionCode = StringVar() 
    self.selectedSectionCode.set("abc") 
 
    abcButton = ttk.Radiobutton(self, text='ABC', variable=self.selectedSectionCode, value='abc',  indicatoron= 0) 
    abcButton.grid(column=0, row=1, sticky=(N,W)) 

但是,当我运行我的代码时,出现以下错误:

  File "C:\Users\...\view.py", line 473, in __init__ 
    abcButton = ttk.Radiobutton(self, text='ABC', value='abc',  indicatoron = 0) 
  File "C:\Python27\lib\lib-tk\ttk.py", line 1073, in __init__ 
    Widget.__init__(self, master, "ttk::radiobutton", kw) 
  File "C:\Python27\lib\lib-tk\ttk.py", line 560, in __init__ 
    Tkinter.Widget.__init__(self, master, widgetname, kw=kw) 
  File "C:\Python27\lib\lib-tk\Tkinter.py", line 1974, in __init__ 
    (widgetName, self._w) + extra + self._options(cnf)) 
clError: unknown option "-indicatoron" 

我不确定为什么这不起作用,并且该站点上有几个示例提到了同样使用 Python 2.7 的用户使用 Radiobutton 小部件使用的这个选项。

我的代码中是否缺少某些内容?

请您参考如下方法:

您链接的文档是针对 Tkinter.Radiobutton 类的。您正在使用 ttk.Radiobutton类,它不支持 indicatoron 属性。