473,395 Members | 1,986 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

wx.TextCtrl.SetDefaultStyle not working?

I'm running Python2.5 with wxPython v2.8.3.0 under WinXP and I cannot
get the SetDefaultStyle method to work.

I'm trying:

self.output.SetDefaultStyle(wx.TextAttr(wx.RED))
self.output.AppendText(text)
self.output.SetDefaultStyle(wx.TextAttr())

where "self.output" is a TextCtrl window. The text appears, but it's
always black. If I print the output of
self.output.GetDefaultStyle().GetTextColour() before resetting it back
to default, I see "(255, 0, 0, 255)". After reset, it's "(-1, -1, -1,
255)".

The font in that window is the system default.

Am I doing something wrong?

-- Brian

Apr 21 '07 #1
3 4637
On Apr 20, 8:38 pm, "bcwh...@pobox.com" <bcwh...@pobox.comwrote:
I'm running Python2.5 with wxPython v2.8.3.0 under WinXP and I cannot
get the SetDefaultStyle method to work.

I'm trying:

self.output.SetDefaultStyle(wx.TextAttr(wx.RED))
self.output.AppendText(text)
self.output.SetDefaultStyle(wx.TextAttr())

where "self.output" is a TextCtrl window. The text appears, but it's
always black. If I print the output of
self.output.GetDefaultStyle().GetTextColour() before resetting it back
to default, I see "(255, 0, 0, 255)". After reset, it's "(-1, -1, -1,
255)".

The font in that window is the system default.

Am I doing something wrong?

-- Brian
You didn't show the code that creates the TextCtrl. Is it something
like this:

self.output = wx.TextCtrl(myFrame, -1, style=wx.TE_MULTILINE |
wx.TE_RICH2)

On my platform, styling the text doesn't work for single line
TextCtrl's(which seems kind of stupid), and on Windows I think you are
required to specify wx.TE_RICH2 to style the text. This following
code colors the entered text red for me:

--------
import wx

myApp = wx.App(False)
myFrame = wx.Frame(None, -1, title="Test")

panel = wx.Panel(myFrame, -1)
my_tc = wx.TextCtrl(myFrame, -1, style=wx.TE_MULTILINE | wx.TE_RICH2)
my_tc.SetDefaultStyle(wx.TextAttr("red") ) #wx.RED works too

myFrame.Show()
myApp.MainLoop()
--------

Apr 21 '07 #2
On my platform, styling the text doesn't work for single line
TextCtrl's(which seems kind of stupid), and on Windows I think you are
required to specify wx.TE_RICH2 to style the text. This following
code colors the entered text red for me:
That's it! I didn't have the TE_RICH2 option set. It works now.

The docs say it's Windows only. Does the GTK version work without
this flag?

-- Brian

Apr 23 '07 #3
On Apr 23, 11:05 am, "bcwh...@pobox.com" <bcwh...@pobox.comwrote:
On my platform, styling the text doesn't work for single line
TextCtrl's(which seems kind of stupid), and on Windows I think you are
required to specify wx.TE_RICH2 to style the text. This following
code colors the entered text red for me:

That's it! I didn't have the TE_RICH2 option set. It works now.

The docs say it's Windows only. Does the GTK version work without
this flag?

-- Brian
I'm not sure what GTK is, but on a Mac that style is ignored if it is
set. Naturally, you can also style the text without that style being
set. So, if you want your program to work cross platform, I assume
you should set that style.

Apr 23 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Logan | last post by:
I asked a similar question already in the wxPython mailing list, but did not get an answer up to now: 1.) When using a TextCtrl with styles (color etc.) in wxPython, is it then possible to get a...
6
by: Hako | last post by:
Hello All, I have a function to set readonly or editable of a textctrl. I'd like to make the textctrl initial set readonly and use other event funciton to set editable of the textctrl but it...
12
by: Simon Hibbs | last post by:
I have a simple form with some input values and some calculated values in TextCtrl widgets. What I would like to do is have the display update automaticaly when the user changes one of the input...
10
by: abcd | last post by:
I have a TextCtrl which is set to be multi-line. I have a function say, updateText(msg), which takes some string and appends it to the text control... txtControl.AppendText(msg) ...
0
by: Erik | last post by:
Is it possible with wxPython to place images in a textctrl (or a styledtextctrl)? If you don't get what I mean, just think about emoticons in the MSN messenger chat window. So is it possible to...
5
by: citronelu | last post by:
I made a small wxPython app that retrieves web data; for visual logging I use a TextCtrl widget, and stdout is redirected to it, something like this: class RedirectOutput: def __init__(self,...
2
by: Pom | last post by:
Hello group! I have an application which uses a lot of mysql data fields, all the same data type (floats). I created a panel which executes a "SELECT * FROM tablename" and makes as much...
3
by: Alejandro | last post by:
Hi: I want to redirect stdout to a textctrl I have. From what I read in the wxpython documentation, I can use the wxLogTextCtrl class to do this. I am doing the following: class...
1
by: aeroumr | last post by:
In the following code, I have created a panel with a button and a textctrl object on it. I have also created a menubar that will create a new text file (i.e. textctrl object). My problem is that...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.