动态wx.RadioButtons

时间:2010-08-08 12:55:52

标签: python wxpython

我在使用下面的程序时遇到了一些麻烦。首先通过程序,一切似乎都正常。随后的传递,标签覆盖了之前没有擦除的标签,加上隐藏按钮的初始循环似乎不起作用。

def drawbutton(self,event):

    rbuttons = [
     wx.RadioButton(self,-1,'xxxxxxxxxx', (190,60),style = wx.RB_GROUP),       
     wx.RadioButton(self, -1,'xxxxxxxxxx', (190,80)),
     wx.RadioButton(self, -1,'xxxxxxxxxx', (190,100)),
     wx.RadioButton(self, -1,'xxxxxxxxxx', (190,120)),
     wx.RadioButton(self, -1,'xxxxxxxxxx', (190,140)),
     wx.RadioButton(self, -1,'xxxxxxxxxx', (190,160)),
     wx.RadioButton(self, -1,'xxxxxxxxxx', (190,180)), ]

    for i in range(7):         
        rbuttons[i].Hide()   


    i = 0

    if self.combobox.GetValue() == "555-1212":
       voice1 = Voice()
       voice1.login("user1","abcdef")
       nphones = len(voice1.phones)



       for i in range(nphones):
           rbuttons[i].SetLabel(voice1.phones[i].name)
           rbuttons[i].Show()

       i = i + 1

       rbuttons[i].SetLabel('Voicemail')
       rbuttons[i].Show()


    else:
       voice2 = Voice()
       voice2.login("user2","abcdef")
       nphones = len(voice2.phones) 
       i = 0  

       for i in range(nphones):
           rbuttons[i].SetLabel(voice2.phones[i].name)
           rbuttons[i].Show()

       i = i + 1

       rbuttons[i].SetLabel('Voicemail')
       rbuttons[i].Show()

1 个答案:

答案 0 :(得分:0)

尝试调用self.Refresh()来强制重绘。

http://www.wxpython.org/docs/api/wx.Window-class.html#Refresh

顺便说一句,你使用'i'的方式在范围上有点令人困惑......

i = 0
....
for i in range(nphones):
           rbuttons[i].SetLabel(voice1.phones[i].name)
           rbuttons[i].Show()

i = i + 1

rbuttons[i].SetLabel('Voicemail')
rbuttons[i].Show()

尝试:

for i in range(nphones):
           rbuttons[i].SetLabel(voice1.phones[i].name)
           rbuttons[i].Show()

vm_idx = nphones    
rbuttons[vm_idx].SetLabel('Voicemail')
rbuttons[vm_idx].Show()