wxPython复选框true或fals

2024-10-08 18:29:22 发布

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

假设我在wxPython中有一个复选框:

cb1 = wx.CheckBox(panelWX, label='TIME', pos=(20, 20))
cb1.SetValue(False)

有没有一个简单的方法我可以检查它是否变为真的? 像这样吧?在

^{pr2}$

从这一点上,附加一些东西从它的行为是真的? 是这样的:

selectionSEM1.append('Time')

Tags: 方法posfalsetimewxpythonlabel复选框wx
2条回答

您只需要使用GetValue()方法。看看wxpython wiki中的这个示例:

#!/usr/bin/python

# checkbox.py

import wx

class MyCheckBox(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, size=(250, 170))

        panel = wx.Panel(self, -1)
        self.cb = wx.CheckBox(panel, -1, 'Show Title', (10, 10))
        self.cb.SetValue(True)

        wx.EVT_CHECKBOX(self, self.cb.GetId(), self.ShowTitle)

        self.Show()
        self.Centre()

    def ShowTitle(self, event):
        if self.cb.GetValue():#here you check if it is true or not
            self.SetTitle('checkbox.py')
        else: self.SetTitle('')


app = wx.App(0)
MyCheckBox(None, -1, 'checkbox.py')
app.MainLoop()

您要使用Events。在

def do_something(event):
    box = event.GetEventObject()
    setting = box.GetValue()
    if setting:
            selectionSEM1.append('Time')
    event.Skip()

cb1.Bind(wx.EVT_CHECKBOX, do_something, cb1)

相关问题 更多 >

    热门问题