Python:根据Radiobox选择在文本框中设置光标

Python:根据Radiobox选择在文本框中设置光标,python,wxpython,Python,Wxpython,我有一个radiobox和一个textctrl,我希望根据radiobox的选择将光标放在textctrl中。我尝试将setfocus用于textctrl,但它不起作用。我正在使用wxpython创建gui。有人能给我指引正确的方向吗 示例代码如下所示 import wx def create(parent): return Frame1(parent) [wxID_FRAME1, wxID_FRAME1NOTEBOOK1, wxID_FRAME1PANEL1, wxID_FRA

我有一个radiobox和一个textctrl,我希望根据radiobox的选择将光标放在textctrl中。我尝试将setfocus用于textctrl,但它不起作用。我正在使用wxpython创建gui。有人能给我指引正确的方向吗

示例代码如下所示

import wx

def create(parent):
    return Frame1(parent)

[wxID_FRAME1, wxID_FRAME1NOTEBOOK1, wxID_FRAME1PANEL1, 
 wxID_FRAME1RADIOBUTTON1, wxID_FRAME1STATICBOX1, wxID_FRAME1STATICTEXT1, 
 wxID_FRAME1TEXTCTRL1, 
] = [wx.NewId() for _init_ctrls in range(7)]

class Frame1(wx.Frame):
    def _init_coll_notebook1_Pages(self, parent):
        # generated method, don't edit

        parent.AddPage(imageId=-1, page=self.panel1, select=True, text='Pages0')
        parent.AddPage(imageId=-1, page=self.staticText1, select=False,
              text='Pages1')

    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
              pos=wx.Point(470, 184), size=wx.Size(363, 201),
              style=wx.DEFAULT_FRAME_STYLE, title='Frame1')
        self.SetClientSize(wx.Size(347, 163))

        self.notebook1 = wx.Notebook(id=wxID_FRAME1NOTEBOOK1, name='notebook1',
              parent=self, pos=wx.Point(0, 0), size=wx.Size(347, 163), style=0)

        self.panel1 = wx.Panel(id=wxID_FRAME1PANEL1, name='panel1',
              parent=self.notebook1, pos=wx.Point(0, 0), size=wx.Size(339, 137),
              style=wx.TAB_TRAVERSAL)

        self.staticBox1 = wx.StaticBox(id=wxID_FRAME1STATICBOX1,
              label='staticBox1', name='staticBox1', parent=self.panel1,
              pos=wx.Point(16, 16), size=wx.Size(232, 80), style=0)

        self.staticText1 = wx.StaticText(id=wxID_FRAME1STATICTEXT1,
              label='staticText1', name='staticText1', parent=self.notebook1,
              pos=wx.Point(0, 0), size=wx.Size(339, 137), style=0)

        self.radioButton1 = wx.RadioButton(id=wxID_FRAME1RADIOBUTTON1,
              label='radioButton1', name='radioButton1', parent=self.panel1,
              pos=wx.Point(32, 48), size=wx.Size(81, 13), style=0)
        self.radioButton1.Bind(wx.EVT_RADIOBUTTON,
              self.OnRadioButton1Radiobutton, id=wxID_FRAME1RADIOBUTTON1)

        self.textCtrl1 = wx.TextCtrl(id=wxID_FRAME1TEXTCTRL1, name='textCtrl1',
              parent=self.panel1, pos=wx.Point(123, 44), size=wx.Size(100, 21),
              style=0, value='')

        self._init_coll_notebook1_Pages(self.notebook1)

    def __init__(self, parent):
        self._init_ctrls(parent)

    def OnRadioButton1Radiobutton(self, event):
        #event.Skip()
        if self.radioButton1.GetValue() == 'True':
            self.textCtrl1.SetFocus()



if __name__ == '__main__':
    app = wx.PySimpleApp()
    frame = create(None)
    frame.Show()

    app.MainLoop()
尝试:

而不是

if self.radioButton1.GetValue() == 'True':
(您发布的代码与此更改相符)

当然,你也可以说:

if self.radioButton1.GetValue():
if self.radioButton1.GetValue():