如何配置 Pmw RadioSelect checkbutton 的状态?
How to configure the state of a Pmw RadioSelect checkbutton?
我有一个 Tk/Pmw 界面,其中有一系列 Pmw.RadioSelect
小部件,其中只有一些应该有活动的复选按钮。根据Pmw docs,组件(如RadioSelect widget中的Tkinter.Checkbutton
)可以配置为使用下划线表示继承。在该页面的示例中,Pmw.Counter
巨型小部件 counter
的 Entryfield
组件中 Tkinter.Entry
小部件的背景可以按以下方式配置。
counter.configure(entryfield_entry_background = 'yellow')
然而,对于 RadioSelect 小部件,按钮组件的名称及其继承并未在文档中明确给出,因为按钮可以是不同类型(button
、radiobutton
, 和 checkbutton
).
如何配置 RadioSelect
小部件的 Checkbutton
组件? 基本上我只需要将正确的字符串作为参数传递给配置。我已经做了一些搜索和试错,但还没有找到正确的参数名称。
作为参考,这是我目前所拥有内容的简化版本。这是一个单独的项目列表,每个项目都可以选中或取消选中,但一些复选框应该处于非活动状态。
for i, f in enumerate(foo):
# Create the RadioSelect widget
chk = Pmw.RadioSelect(parent,
buttontype='checkbutton',
command=self.checkbutton_callback)
# Add a numbered checkbutton
chk.add(str(i))
# Place it on the grid
chk.grid(row=i, column=0)
# Without the following code, it works fine, but all the buttons are enabled
# With it, the program chokes on the `configure()` call
if not f.active:
print "This gets printed."
chk.configure(checkbutton_state='disabled')
print "But this doesn't."
很明显,倒数第二行的 checkbutton_state
是错误的参数名称。我应该改用什么?
add()
方法 returns 组件小部件。这意味着您可以修改此行:
chk.add(str(i))
收件人:
my_checkbutton = chk.add(str(i))
记住这一点。现在要使用 my_checkbutton
,你必须创建一个 Tkinter 变量 my_var = IntVar()
因为如果你想检查 my_checkbutton
的状态,查询 my_var
.
如果您不清楚,我可以提供您我的示例程序。上面是哪个截图:
我有一个 Tk/Pmw 界面,其中有一系列 Pmw.RadioSelect
小部件,其中只有一些应该有活动的复选按钮。根据Pmw docs,组件(如RadioSelect widget中的Tkinter.Checkbutton
)可以配置为使用下划线表示继承。在该页面的示例中,Pmw.Counter
巨型小部件 counter
的 Entryfield
组件中 Tkinter.Entry
小部件的背景可以按以下方式配置。
counter.configure(entryfield_entry_background = 'yellow')
然而,对于 RadioSelect 小部件,按钮组件的名称及其继承并未在文档中明确给出,因为按钮可以是不同类型(button
、radiobutton
, 和 checkbutton
).
如何配置 RadioSelect
小部件的 Checkbutton
组件? 基本上我只需要将正确的字符串作为参数传递给配置。我已经做了一些搜索和试错,但还没有找到正确的参数名称。
作为参考,这是我目前所拥有内容的简化版本。这是一个单独的项目列表,每个项目都可以选中或取消选中,但一些复选框应该处于非活动状态。
for i, f in enumerate(foo):
# Create the RadioSelect widget
chk = Pmw.RadioSelect(parent,
buttontype='checkbutton',
command=self.checkbutton_callback)
# Add a numbered checkbutton
chk.add(str(i))
# Place it on the grid
chk.grid(row=i, column=0)
# Without the following code, it works fine, but all the buttons are enabled
# With it, the program chokes on the `configure()` call
if not f.active:
print "This gets printed."
chk.configure(checkbutton_state='disabled')
print "But this doesn't."
很明显,倒数第二行的 checkbutton_state
是错误的参数名称。我应该改用什么?
add()
方法 returns 组件小部件。这意味着您可以修改此行:
chk.add(str(i))
收件人:
my_checkbutton = chk.add(str(i))
记住这一点。现在要使用 my_checkbutton
,你必须创建一个 Tkinter 变量 my_var = IntVar()
因为如果你想检查 my_checkbutton
的状态,查询 my_var
.
如果您不清楚,我可以提供您我的示例程序。上面是哪个截图: