【问题标题】:wxPython checkbox true or falsewxPython 复选框 true 或 false
【发布时间】:2014-06-17 17:20:34
【问题描述】:

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

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

有没有一种简单的方法可以检查它是否已更改为 true? 可能是这样?

if cb1.SetValue == True:

从那时起,从它是真的动作中附加一些东西? 像这样:

selectionSEM1.append('Time')

【问题讨论】:

  • 我不在乎它是否再次变为假,只要它在任何时候都变为真。

标签: python wxpython append


【解决方案1】:

你只需要使用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()

【讨论】:

    【解决方案2】:

    你想使用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)
    

    【讨论】:

    • 但是我怎样才能让事件将某些内容附加到主方法中存在的列表中呢?据我所知,我无法在其中添加额外的参数。
    • @LukeG,你对 OOP 有多熟悉?对象的任何属性(无论它们是否在 main 中声明)都应该可以被该对象的方法访问。如果问题中没有额外的信息,很难提供更具体的帮助。
    猜你喜欢
    • 1970-01-01
    • 2014-06-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-11
    • 2013-05-26
    相关资源
    最近更新 更多