How to take value from textctrl in wxpython

Here is python python. It contains a text ctrl and a button. Please help me change so that when I click the button, I need a line entered in textctrl to save in a variable.

#! /usr/bin/env python
#Boa:Frame:Frame1

import wx

def create(parent):
    return Frame1(parent)

[wxID_FRAME1, wxID_FRAME1BUTTON1, wxID_FRAME1PANEL1, wxID_FRAME1TEXT1, 
] = [wx.NewId() for _init_ctrls in range(4)]

class Frame1(wx.Frame):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
              pos=wx.Point(249, 224), size=wx.Size(683, 445),
              style=wx.DEFAULT_FRAME_STYLE, title='Frame1')
        self.SetClientSize(wx.Size(683, 445))

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

        self.text1 = wx.TextCtrl(id=wxID_FRAME1TEXT1, name=u'text1',
              parent=self.panel1, pos=wx.Point(268, 139), size=wx.Size(103, 25),
              style=0, value=u'enter')

        self.button1 = wx.Button(id=wxID_FRAME1BUTTON1, label=u'click',
              name='button1', parent=self.panel1, pos=wx.Point(279, 272),
              size=wx.Size(85, 27), style=0)
        self.button1.Bind(wx.EVT_BUTTON, self.OnButton1Button,
              id=wxID_FRAME1BUTTON1)

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

    def OnButton1Button(self, event):
        event.Skip()


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

    app.MainLoop()
+3
source share
1 answer

There is a method attached to a wxTextCtrl object called getValue , so in OnButton1Button () you call

var = self.text1.GetValue()

Then do what you want with var.

+4
source

All Articles