从文本控件获取字符串

15 投票
2 回答
25628 浏览
提问于 2025-04-15 17:54

如何从一个 TextCtrl 盒子中获取字符串?下面是练习代码:

import wx



class citPanel(wx.Panel):
    def __init__(self, parent, id):
        wx.Panel.__init__(self, parent, id)


        wx.StaticText(self, -1, "Choose put you would like:", (45, 15))

        self.quote = wx.StaticText(self, -1, "1:", wx.Point(275, 180), wx.Size(200, -1))
        self.quote = wx.StaticText(self, -1, "2:", wx.Point(275, 230), wx.Size(200, -1))
        self.quote = wx.StaticText(self, -1, "3:", wx.Point(275, 280), wx.Size(200, -1))




class nextButton(wx.Button):
    def __init__(self, parent, id, label, pos):
        wx.Button.__init__(self, parent, id, label, pos)

class cancelButton(wx.Button):
    def __init__(self, parent, id, label, pos):
        wx.Button.__init__(self, parent, id, label, pos)

class searchBox(wx.TextCtrl):
def __init__(self, parent, id, name, pos):
    wx.TextCtrl.__init__(self, parent, id, name, pos)



class minBox(wx.TextCtrl):
    def __init__(self, parent, id, name, pos):
        wx.TextCtrl.__init__(self, parent, id, name, pos)

class maxBox(wx.TextCtrl):
    def __init__(self, parent, id, name, pos):
        wx.TextCtrl.__init__(self, parent, id, name, pos)


class checkList(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, size=(600, 600))

        self.panel = citPanel(self, -1)

        self.searchCtrl = searchBox(self.panel, -1, '', (275, 200))
        self.Bind(wx.EVT_TEXT, self.EvtText)
        self.minCtrl = minBox(self.panel, -1, '', (275, 250))
        self.Bind(wx.EVT_TEXT, self.EvtText1)
        self.maxCtrl = maxBox(self.panel, -1, '', (275, 300))
        self.Bind(wx.EVT_TEXT, self.EvtText2)
        nextButton(self.panel, 30, 'Ok', (275, 50))
        cancelButton(self.panel, -1, 'Exit', (275, 75))
        self.Bind(wx.EVT_BUTTON, self.Clicked)



        self.Centre()
        self.Show(True)

    def EvtText(self, event):
        num1 = event.GetString()

    def EvtText1(self, event):
        num2 = event.GetString()


    def EvtText2(self, event):
        num3 = event.GetString()


    def Clicked(self, event):

        combo = num1 + num2 + num3

        print combo


        event.Skip()




app = wx.App()
checkList(None, -1, 'Charlie')
app.MainLoop()

2 个回答

3

使用 GetValue(),不要用 GetString()

看看这个API文档:http://docs.wxwidgets.org/stable/wx_wxtextctrl.html

28

在编程中,有时候我们需要把一些数据从一个地方传到另一个地方。这个过程就像把水从一个水壶倒到另一个水壶一样。我们需要确保水不会洒出来,也就是数据在传输过程中不会丢失。

为了做到这一点,程序员们会使用一些特定的工具和方法。这些工具和方法可以帮助我们更安全、更有效地传输数据。比如,有些工具可以检查数据是否完整,确保在传输过程中没有错误发生。

此外,传输的数据可能会有不同的格式,就像不同的水壶可能有不同的形状。我们需要确保在传输之前,数据的格式是合适的,这样才能顺利地进行。

总之,数据传输就像是一个精细的过程,我们需要小心翼翼地处理,确保每一步都能顺利进行。

TextCtrlInstance.GetValue()

撰写回答