How to get the strings from a TextCtrl
box? Here is the practice code:
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()
In the following example, four objects of wx.TextCtrl class with different attributes are placed on the panel. While the first is a normal text box, the second is a password field. The third one is a multiline text box and the last text box is non-editable.
In wxPython, an object of wx.TextCtrl class serves this purpose. It is a control in which the text can be displayed and edited. The TextCtrl widget can be a single line, multi-line or a password field. TextCtrl class constructor takes the following form − wx.TextCtrl(parent, id, value, pos, size, style)
This widget can be used for messaging, displaying information, and many other tasks. The important task is to get the inserted text for further processing. For this, we have to use the get () method for the textbox widget.
TextRange provides a Text property, which returns the plain text portions of the TextRange as a string. Private Function StringFromRichTextBox (ByVal rtb As RichTextBox) As String ' TextPointer to the start of content in the RichTextBox. ' TextPointer to the end of content in the RichTextBox.
TextCtrlInstance.GetValue()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With