使用 wxpython 的单选按钮

发布于 2024-12-07 22:47:01 字数 570 浏览 1 评论 0原文

我正在使用 wxpython 构建一个 gui.. 其中有按钮和单选按钮,我想

根据 gui 中小部件的当前值来执行此类任务.. 插入

按钮有多个 if 语句其中之一if 语句用于检查

单选按钮是否被选中。我不想将事件绑定到单选按钮,所以我已经

在插入按钮中检查了它,使用

这是定义的单选按钮

self.rb1 = wx.RadioButton(self.panel, -1, 'Is this a required pre_action to the next   

step?', (5, 220))

,这是检查条件

if self.rb1.GetValue():

    # do something here

,而且:

if self.rb1.GetValue() == 'True':

  # do some tasks

在两种方式(已经相同)中什么都没有当我选择单选按钮

rb1 时发生!那么这有什么问题呢?

I'm Building a gui using wxpython.. i have buttons and radiobuttons in it, and i wanna

to do such tasks based on what the current values of the widgets in the gui .. the insert

button has a multiple if statement one of these if statement is to check whether a

radiobutton is selected. i dont want to bind an event to the radio button so i have

checked about it in the insert button using

this is the defined radion button

self.rb1 = wx.RadioButton(self.panel, -1, 'Is this a required pre_action to the next   

step?', (5, 220))

and this is the check condition

if self.rb1.GetValue():

    # do something here

and also :

if self.rb1.GetValue() == 'True':

  # do some tasks

in both way (which is already the same) the is nothing happend when i choose the radio

button rb1 ! so what is the problwm of this ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

泛泛之交 2024-12-14 22:47:01

我不知道什么对你不起作用。它对我来说效果很好。请参阅下面的示例代码:

import wx

class MyForm(wx.Frame):

    #----------------------------------------------------------------------
    def __init__(self):
        wx.Frame.__init__(self, None, wx.ID_ANY, "Tutorial")
        panel = wx.Panel(self, wx.ID_ANY)

        self.radio = wx.RadioButton(panel, label="Test", style = wx.RB_GROUP)
        self.radio2 = wx.RadioButton(panel, label="Test2")

        btn = wx.Button(panel, label="Check Radio")
        btn.Bind(wx.EVT_BUTTON, self.onBtn)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.radio, 0, wx.ALL, 5)
        sizer.Add(self.radio2, 0, wx.ALL, 5)
        sizer.Add(btn, 0, wx.ALL, 5)
        panel.SetSizer(sizer)

    #----------------------------------------------------------------------
    def onBtn(self, event):
        """"""
        print "First radioBtn = ", self.radio.GetValue()
        print "Second radioBtn = ", self.radio2.GetValue()

# Run the program
if __name__ == "__main__":
    app = wx.PySimpleApp()
    frame = MyForm().Show()
    app.MainLoop()

I don't know what that doesn't work for you. It works for me just fine. See sample code below:

import wx

class MyForm(wx.Frame):

    #----------------------------------------------------------------------
    def __init__(self):
        wx.Frame.__init__(self, None, wx.ID_ANY, "Tutorial")
        panel = wx.Panel(self, wx.ID_ANY)

        self.radio = wx.RadioButton(panel, label="Test", style = wx.RB_GROUP)
        self.radio2 = wx.RadioButton(panel, label="Test2")

        btn = wx.Button(panel, label="Check Radio")
        btn.Bind(wx.EVT_BUTTON, self.onBtn)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.radio, 0, wx.ALL, 5)
        sizer.Add(self.radio2, 0, wx.ALL, 5)
        sizer.Add(btn, 0, wx.ALL, 5)
        panel.SetSizer(sizer)

    #----------------------------------------------------------------------
    def onBtn(self, event):
        """"""
        print "First radioBtn = ", self.radio.GetValue()
        print "Second radioBtn = ", self.radio2.GetValue()

# Run the program
if __name__ == "__main__":
    app = wx.PySimpleApp()
    frame = MyForm().Show()
    app.MainLoop()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文