hi,
im trying to do something like the following:

text_area = wx.TextCtrl(self.panel, -1, style=wx.MULTILINE)
a = (all the text in the text control window)

I can't get my head around how to define the text with wxpython, how should I go about this?

Recommended Answers

All 2 Replies

umm something along the lines of a = getvalue(textarea)

not completely sure of the syntax but its along those lines. sorry i could be of more help
maybe...

a = self.GetValue(text_area)

Here would be simple example ...

# explore wxPython wx.Frame with
# a wx.TextCtrl to enter some text
# a wx.Button to start process action
# a wx.StaticText to display the result

import wx

class MyFrame(wx.Frame):
    def __init__(self, parent, mytitle):
        wx.Frame.__init__(self, parent, -1, mytitle)
        self.SetBackgroundColour("yellow")

        # create some widgets
        self.edit = wx.TextCtrl(self, -1, value="", size=(350, 50),
            style=wx.TE_MULTILINE)
        self.button = wx.Button(self, -1, label="Press to process")
        self.label = wx.StaticText(self, -1, size=(350, 90))

        # stack the widgets vertically
        myflag = wx.ALL|wx.EXPAND
        sizer_v = wx.BoxSizer(wx.VERTICAL)
        sizer_v.Add(self.edit, flag=myflag, border=10)
        sizer_v.Add(self.button, flag=myflag, border=10)
        sizer_v.Add(self.label, flag=myflag, border=10)
        # make the frame fit all the widgets
        self.SetSizerAndFit(sizer_v)

        # bind button mouse click event to an action
        self.button.Bind(wx.EVT_BUTTON, self.onAction)
        
    def onAction(self, event):
        """
        get the text from edit, process it and display in label
        """
        text = self.edit.GetValue()
        # optional text processing
        if not text:
            text = "any text entered would look like this"
        text = text.upper()
        self.label.SetLabel(text)


app = wx.App(0)
# create a MyFrame instance and show the frame
MyFrame(None, "enter some text and process it").Show()
app.MainLoop()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.