2016-01-13 35 views
1

我有一个Tk/Pmw接口,它有一系列Pmw.RadioSelect小部件,只有其中的一些应该有活动的检查按钮。根据Pmw docs,可以使用下划线配置组件(如RadioSelect小部件中的Tkinter.Checkbutton)以指示继承。在该页面上的示例中,可以按照以下方式配置Pmw.Counter兆字节组件Entryfield组件中的Tkinter.Entry窗口小部件的背景,该组件位于。如何配置Pmw RadioSelect检查按钮的状态?

counter.configure(entryfield_entry_background = 'yellow') 

对于RadioSelect窗口小部件,但是,按钮组件及其继承的名称没有明确的文件中给出的,因为按钮可以是不同类型(buttonradiobuttoncheckbutton)。

如何配置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在第二到最后一行是错误的参数名称。我应该用什么来代替?

回答

0

add()方法返回组件小部件。这意味着你可以修改此行:

chk.add(str(i)) 

要:

my_checkbutton = chk.add(str(i)) 

记住将这个。现在要使用my_checkbutton,您必须创建一个Tkinter变量my_var = IntVar(),因为如果要检查my_checkbutton的状态,请查询my_var

如果您不清楚,我可以为您提供我的示例程序。其截图如上:

enter image description here