How to set wxTextCtrl style to wxHSCROLL?

T

Tim

How can I set the style attribute in the following wxTextCtrl to a new
style AFTER I have already instantiated the wxTextCtrl? I'm trying to
toggle the word wrap attribute of the wxTextCtrl, just like Edit->Word
Wrap does in Windows Notepad. (I'm building a Windows Notepad clone
in wxPython to prove to a VB friend that it can be done.)

Here is the wxTextCtrl instantiation:

--------------
self.txtEditor = wxTextCtrl(id=wxID_WXFRAME1TXTEDITOR,
name='txtEditor',
parent=self, pos=wxPoint(0, 0), size=wxSize(760, 492),
style=wxTE_MULTILINE, value='')
--------------

Here is the code I've tried to set the style to a new value:

--------------
def OnMnuEditWordwrapMenu(self, event):
# TODO: implement word wrap
self.txtEditor.SetStyle(0, self.txtEditor.GetLastPosition(),
wxHSCROLL)
#self.txtEditor.style = 'wxHSCROLL'

--------------

What is the correct syntax?

Thanks!

Tim
 
T

Tom B.

Tim said:
How can I set the style attribute in the following wxTextCtrl to a new
style AFTER I have already instantiated the wxTextCtrl? I'm trying to
toggle the word wrap attribute of the wxTextCtrl, just like Edit->Word
Wrap does in Windows Notepad. (I'm building a Windows Notepad clone
in wxPython to prove to a VB friend that it can be done.)

Here is the wxTextCtrl instantiation:

--------------
self.txtEditor = wxTextCtrl(id=wxID_WXFRAME1TXTEDITOR,
name='txtEditor',
parent=self, pos=wxPoint(0, 0), size=wxSize(760, 492),
style=wxTE_MULTILINE, value='')
--------------

Here is the code I've tried to set the style to a new value:

--------------
def OnMnuEditWordwrapMenu(self, event):
# TODO: implement word wrap
self.txtEditor.SetStyle(0, self.txtEditor.GetLastPosition(),
wxHSCROLL)
#self.txtEditor.style = 'wxHSCROLL'

--------------

What is the correct syntax?

Thanks!

Tim
I might try
import wx

self.txtEditor.style = wx.HSCROLL
#wx.HSCROLL if an integer constant
self.txtEditor.Refresh()

You should be useing something like wx.StyledTextCtrl which has all of the
functionality built in. One thing you don't need to prove to any programmer
is that Python can be as difficult as any language. Find the proper library
to do your task, import it and use it.

Tom
 
T

Tim

Thank you! I couldn't get the wxTextCtrl style to change using the
method you suggested, but I tried the StyledTextCtrl which works
wonderfully! : ) It made the more complex functionality easier to
implement all-around.

Tim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top