在wxPython中的复选框单击事件上设置标签值

时间:2015-05-05 10:13:12

标签: checkbox wxpython

在复选框上单击事件集标签作为某些文本。如果我们单击Text复选框,则应将名为abt_Metric的标签设置为Text Collected。

boxsizer = wx.StaticBoxSizer(sb, wx.VERTICAL)
#adding checkBox
c1 = wx.CheckBox(panel, label="Text")
#c1.SetValue(True)



#abt_Metric= wx.StaticText(panel, label='')
#boxsizer.Add(abt_Metric, flag=wx.LEFT|wx.TOP,border=10)
#result.GetValue()
url_entered.SetForegroundColour(wx.BLUE)


c2 = wx.CheckBox(panel, label="HTML ")
#c2.SetValue(True)
c3 = wx.CheckBox(panel, label="NLP")
#c3.SetValue(True)



boxsizer.Add(c1,flag=wx.LEFT|wx.TOP, border=5)
boxsizer.Add(c2,flag=wx.LEFT, border=5)
boxsizer.Add(c3,flag=wx.LEFT|wx.BOTTOM, border=5)
sizer.Add(boxsizer, pos=(6, 0), span=(1, 5),flag=wx.EXPAND|wx.TOP|wx.LEFT|wx.RIGHT , border=10)


abt_Metric= wx.StaticText(panel, label='')

sizer.Add(abt_Metric, pos=(7, 0), flag=wx.LEFT|wx.TOP,border=10)

复选框事件处理程序

c1.Bind(wx.EVT_CHECKBOX, self.OntextMetric(c1),c1)
c2.Bind(wx.EVT_CHECKBOX, self.OntextMetric(c2),c2)
c3.Bind(wx.EVT_CHECKBOX, self.OntextMetric(c3),c3)

def OntextMetric(self,e,c)

的实施
if c.GetValue() == True:

    self.panel.abt_Metric.SetLabel(" Text collected")
elif c.GetValue() == True:
    self.panel.abt_Metric.SetLabel("HTML collected")
elif c.GetValue() == True:
    self.panel.abt_Metric.SetLabel("NLP Collected")
else:
    self.panel.abt_Metric.SetLabel("")

1 个答案:

答案 0 :(得分:0)

我无法清楚地理解你的问题,但这是你在寻找什么?

import wx
import matplotlib
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
from matplotlib.figure import Figure

class MainFrame(wx.Frame): 
    def __init__(self): 
        wx.Frame.__init__(self, None, wx.NewId(), "Main")
        panel = wx.Panel(self,1)
        #sizer = wx.BoxSizer(wx.HORIZONTAL)
        boxsizer = wx.BoxSizer(wx.VERTICAL)
        c1 = wx.CheckBox(panel, label="Text")
        c2 = wx.CheckBox(panel, label="HTML ")
        c3 = wx.CheckBox(panel, label="NLP")
        c1.Bind(wx.EVT_CHECKBOX, self.OntextMetric, c1)
        c2.Bind(wx.EVT_CHECKBOX, self.OntextMetric,c2)
        c3.Bind(wx.EVT_CHECKBOX, self.OntextMetric,c3)
        self.abt_Metric= wx.StaticText(panel, label='')
        boxsizer.Add(c1,flag=wx.LEFT, border=5)
        boxsizer.Add(c2,flag=wx.LEFT, border=5)
        boxsizer.Add(c3,flag=wx.LEFT, border=5)

        boxsizer.Add(self.abt_Metric, flag = wx.LEFT)
        panel.SetSizer(boxsizer)

    def OntextMetric(self,event):
        if event.IsChecked():
            self.abt_Metric.SetLabel(event.GetEventObject().GetLabel() + "collected")

class MyApp(wx.App):
    def OnInit(self):
        frame = MainFrame()
        frame.Show(True)
        self.SetTopWindow(frame)
        return True

app = MyApp(0)
app.MainLoop()    

enter image description here