如何在wxPython中记录多个复选框?

2024-09-30 14:16:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图让我的程序记录如果用户点击了复选框,这样我就知道要删除什么。问题是我没有所有复选框的所有变量名,所以我不能只做GetValue()。在下面的代码中,我有一组东西,但在实际的程序中,它从文件中提取用户信息。在

import wx
class supper(wx.Frame):
    def __init__(self,parent,id):
        wx.Frame.__init__(self,parent,id,'Delete Stocks',size=(300,300))
        nexus=wx.Panel(self)
        again=30
        newfp='GOOG AAPL'.split()
        #Need to see if user checked box and which one
        for i in newfp:
            self.checkbox=(wx.CheckBox(nexus,-1,i,(30,again),(160,-1)))
            self.Bind(wx.EVT_CHECKBOX, self.lol,self.checkbox)
            again+=30
        anothercancel=wx.Button(nexus,label='Cancel',pos=(50,250),size=(60,40))
        self.Bind(wx.EVT_BUTTON,self.acancel,anothercancel)
        anotherok=wx.Button(nexus,label='OK',pos=(200,250),size=(60,40))
        self.Bind(wx.EVT_BUTTON,self.okalready,anotherok)
    def acancel(self,event):
        self.Destroy()
    #Couldn't figure out how to see what check was clicked
    def okalready(self,event):
        for i in newfp:
            valuechecker=self.checkbox.GetValue()
            if self.checkbox.Get()==True:
                print 'You clicked this %s one'%i
        self.Destroy()
    def lol(self,event):
        pass
if __name__=='__main__':
    ok=wx.PySimpleApp()
    people=supper(parent=None,id=-1)
    people.Show()
    ok.MainLoop()

这不是全部,所以可能有一个变量没有在这里定义。提前谢谢!期待答案!在


Tags: self程序eventnexusidsizeifbind
1条回答
网友
1楼 · 发布于 2024-09-30 14:16:24

把它们列在一个单子里。。。在

self.checkboxes = []
for i in newfp:
        self.checkboxes.append(wx.CheckBox(nexus,-1,i,(30,again),(160,-1)))
        self.checkboxes[-1].Bind(wx.EVT_CHECKBOX, self.lol)
        again+=30

然后,要在单击“确定”时选中哪些框,可以使用此选项

^{pr2}$

相关问题 更多 >

    热门问题