2016-01-13 33 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