0

我有一个单选框和一个 textctrl,我想根据单选框选择将光标放在 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()
4

1 回答 1

0

尝试:

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

代替

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

(您发布的代码可以根据需要使用此更改)

当然你也可以放:

if self.radioButton1.GetValue():
于 2013-08-08T02:14:30.737 回答