Sending string or list to WxTextCtrl

Need help sending text to a wxTextCtrl when a button is clicked.

Made a small gui trying to learn wxPython. It has two buttons,
menus and a TextCtrl (multiline). Have the menus and button events
working.

Have been able to get the button working on, to print Text to the
console screen when start App with the console. Cannot send to the
TextCtrl though.

Little info:

wxGlade made two classes in the generated file.

class MyNotebook(wxNotebook):
...(buttons and textctrl(readonly, multline))
class MyFrame(wxFrame):
...(menus)

The buttons and TextCtrl are in the Notebook class. Trying to keep the
commandline functionality of the program writing a gui for so want
to keep the Gui seperate form the program. So right now following
the example from: http://wiki.wxpython.org/index.cgi/OrganizingYourCode
where he is using a main.py to start the gui.

Perferably would like to send stdout to the TextCtrl (tried one tutorial
on wiki.wxpython.org for that an didn't work.) But if have to would
be able to have the program write to a file and send the file to TextCtrl.

Do you have any hints, ideas, better examples on the web.

Here is the total main.py script calling the Gui1.py generated file.

Main.py

···

***************************************************************
#!/usr/bin/python

from wxPython.wx import *
from Gui1 import *

ID_COMBO = wxNewId()

# First doing MyApp to just launch it. will add functionality later
class MyApp(wxApp):
  def OnInit(self):
    # Display the main frame of the App
    frame = MyFrame(None,-1,"")
    frame.Show(True)
    #self.SetTopWindow(frame)
    self.frame = frame
    
    # Menu Events
    EVT_MENU(self,ID_EXIT,self.MenuExit)
    #EVT_MENU(self,frame.ID_ABOUT,self.MenuAbout)
    # Adding a button that is the main window
    EVT_BUTTON(self,ID_SHOW,self.onButtonShow)

    return True

  def MenuExit(self,event):
    self.frame.Close(true)
    
  def onButtonShow(self,event):
    This is the section can't get working.
    EVT_MENU sends it here when button pressed.
    But can't make text go to the Gui TextCtrl.

def main():
  app = MyApp(0)
  app.MainLoop()

if __name__ == '__main__':
  main()
***************************************************************

Thanks, Dave

David wrote:

Need help sending text to a wxTextCtrl when a button is clicked.

Made a small gui trying to learn wxPython. It has two buttons,
menus and a TextCtrl (multiline). Have the menus and button events
working.

Have been able to get the button working on, to print Text to the
console screen when start App with the console. Cannot send to the
TextCtrl though.

You need to keep a reference to the textctrl and then just call it's SetValue method:

  self.textctrl.SetValue("Hello")

Little info:

wxGlade made two classes in the generated file.

<soapbox>
RAD Code generators are very nice, but IMO you should not use them until you can understand the code they generate and you could do the same thing they do by hand. (No offense intended to Alberto and others, it's just my opinion.) Only when you understand what they are doing should you use the RAD tool to save you gobs of time.
</soapbox>

class MyNotebook(wxNotebook):
...(buttons and textctrl(readonly, multline))
class MyFrame(wxFrame):
...(menus)

The buttons and TextCtrl are in the Notebook class. Trying to keep the
commandline functionality of the program writing a gui for so want
to keep the Gui seperate form the program. So right now following
the example from: http://wiki.wxpython.org/index.cgi/OrganizingYourCode
where he is using a main.py to start the gui.

Perferably would like to send stdout to the TextCtrl (tried one tutorial
on wiki.wxpython.org for that an didn't work.) But if have to would
be able to have the program write to a file and send the file to TextCtrl.

Do you have any hints, ideas, better examples on the web.

Be sure to look at the code in the demo application. It is meant to be used as a teaching/experimenting tool. Also, the attached sample may help.

counter.py (1.08 KB)

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!