The Method I was told when asking a similar question was to change the
font attributes of the parent window:
import wx
import os
ID_BUTTON1=110
class MainWindow(wx.Frame):
def __init__(self,parent,id,title):
self.dirname=''
wx.Frame.__init__(self,parent,wx.ID_ANY, title)
self.control = wx.TextCtrl(self, 1, style=wx.TE_MULTILINE)
wx.EVT_MENU(self, ID_ABOUT, self.OnAbout)
wx.EVT_MENU(self, ID_EXIT, self.OnExit)
wx.EVT_MENU(self, ID_OPEN, self.OnOpen)
self.sizer2 = wx.BoxSizer(wx.HORIZONTAL)
self.buttons=[]
for i in range(0,5):
self.SetFont(wx.Font(2+2*i,wx.FONTFAMILY_MODERN,wx.FONTSTYLE_NORMAL,wx.FONTWEIGHT_NORMAL,
faceName="Courier New"))
self.buttons.append(wx.Button(self, ID_BUTTON1+i, "Button
&"+str(i+1)))
self.sizer2.Add(self.buttons[i],1,wx.EXPAND)
## Use some sizers to see layout options
sizer=wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.control,1,wx.EXPAND) ## the control (editor) aspect
ratio changes with frame size
#self.sizer.Add(self.control,1,wx.SHAPED) ## the control aspect
ratio is set, and will not change
sizer.Add(self.sizer2,0,wx.EXPAND) ## Likewise, for the buttons
#self.sizer.Add(self.sizer2,0,wx.SHAPED)
##Layout sizers
self.SetSizer(sizer)
self.SetAutoLayout(1)
sizer.Fit(self)
self.Show(1)
app = wx.PySimpleApp()
frame = MainWindow(None, -1, "Sample editor")
app.MainLoop()
Note the line:
self.SetFont(wx.Font(2+2*i,wx.FONTFAMILY_MODERN,wx.FONTSTYLE_NORMAL,wx.FONTWEIGHT_NORMAL,
faceName="Courier New"))
this changes all widgets in the frame to this font. In this case I make
the buttons go from size 2pt (2+2*0) font to 10pt (2+2*4).
I personally would prefer to change just the widget, but everything I have
tried in that vein has failed.
Hope this helps,
-Brian
Brian Fett
1280 Disc Dr
SHK224
Shakopee, MN 55379
Phone: (952)402-2595
[email protected]
Joost van Doremalen <[email protected]>
Sent by: [email protected]
No Phone Info Available
07/14/2008 12:11 PM
Please respond to
[email protected]
To
<[email protected]>
cc
Subject
[wxpython-users] button labels with different font colors and styles
Hi all,
I want to put a text label on a button, but the label has different colors
and styles:
some words are marked blue and are bold, other words are formatted
normally.
I haven't found a way to do this. Is this possible? if yes, how can I
achieve this?
Regards,
Joost
_________________________________________________________________
Use video conversation to talk face-to-face with Windows Live Messenger.
http://www.windowslive.com/messenger/connect_your_way.html?ocid=TXT_TAGLM_WL_Refresh_messenger_video_072008_______________________________________________
wxpython-users mailing list
[email protected]
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users
<br><font size=2 face="sans-serif">The Method I was told when asking a
similar question was to change the font attributes of the parent window:</font>
<br>
<br><font size=2 face="sans-serif">import wx</font>
<br><font size=2 face="sans-serif">import os</font>
<br><font size=2 face="sans-serif">ID_BUTTON1=110</font>
<br><font size=2 face="sans-serif">class MainWindow(wx.Frame):</font>
<br><font size=2 face="sans-serif"> def __init__(self,parent,id,title):</font>
<br><font size=2 face="sans-serif"> self.dirname=''</font>
<br><font size=2 face="sans-serif"> wx.Frame.__init__(self,parent,wx.ID_ANY,
title)</font>
<br><font size=2 face="sans-serif"> self.control =
wx.TextCtrl(self, 1, style=wx.TE_MULTILINE)</font>
<br><font size=2 face="sans-serif"> wx.EVT_MENU(self,
ID_ABOUT, self.OnAbout)</font>
<br><font size=2 face="sans-serif"> wx.EVT_MENU(self,
ID_EXIT, self.OnExit)</font>
<br><font size=2 face="sans-serif"> wx.EVT_MENU(self,
ID_OPEN, self.OnOpen)</font>
<br><font size=2 face="sans-serif"> self.sizer2 = wx.BoxSizer(wx.HORIZONTAL)</font>
<br><font size=2 face="sans-serif"> self.buttons=[]</font>
<br><font size=2 face="sans-serif"> for i in range(0,5):</font>
<br><font size=2 face="sans-serif"> self.SetFont(wx.Font(2+2*i,wx.FONTFAMILY_MODERN,wx.FONTSTYLE_NORMAL,wx.FONTWEIGHT_NORMAL,
faceName="Courier New"))</font>
<br><font size=2 face="sans-serif"> self.buttons.append(wx.Button(self,
ID_BUTTON1+i, "Button &"+str(i+1)))</font>
<br><font size=2 face="sans-serif"> self.sizer2.Add(self.buttons[i],1,wx.EXPAND)</font>
<br><font size=2 face="sans-serif"> ## Use some sizers
to see layout options</font>
<br><font size=2 face="sans-serif"> sizer=wx.BoxSizer(wx.VERTICAL)</font>
<br><font size=2 face="sans-serif"> sizer.Add(self.control,1,wx.EXPAND)
## the control (editor) aspect ratio changes with frame size</font>
<br><font size=2 face="sans-serif"> #self.sizer.Add(self.control,1,wx.SHAPED)
## the control aspect ratio is set, and will not change</font>
<br><font size=2 face="sans-serif"> sizer.Add(self.sizer2,0,wx.EXPAND)
## Likewise, for the buttons</font>
<br><font size=2 face="sans-serif"> #self.sizer.Add(self.sizer2,0,wx.SHAPED)</font>
<br><font size=2 face="sans-serif"> ##Layout sizers</font>
<br><font size=2 face="sans-serif"> self.SetSizer(sizer)</font>
<br><font size=2 face="sans-serif"> self.SetAutoLayout(1)</font>
<br><font size=2 face="sans-serif"> sizer.Fit(self)</font>
<br><font size=2 face="sans-serif"> self.Show(1)</font>
<br><font size=2 face="sans-serif">app = wx.PySimpleApp()</font>
<br><font size=2 face="sans-serif">frame = MainWindow(None, -1, "Sample
editor")</font>
<br><font size=2 face="sans-serif">app.MainLoop()</font>
<br>
<br><font size=2 face="sans-serif">Note the line:</font>
<br><font size=2 face="sans-serif">self.SetFont(wx.Font(2+2*i,wx.FONTFAMILY_MODERN,wx.FONTSTYLE_NORMAL,wx.FONTWEIGHT_NORMAL,
faceName="Courier New"))</font>
<br><font size=2 face="sans-serif">this changes all widgets in the frame
to this font. In this case I make the buttons go from size 2pt (2+2*0)
font to 10pt (2+2*4). </font>
<br>
<br><font size=2 face="sans-serif">I personally would prefer to change
just the widget, but everything I have tried in that vein has failed.</font>
<br>
<br><font size=2 face="sans-serif">Hope this helps,</font>
<br><font size=2 face="sans-serif"><br>
-Brian<br>
<br>
Brian Fett<br>
1280 Disc Dr<br>
SHK224<br>
Shakopee, MN 55379<br>
<br>
Phone: (952)402-2595<br>
Brian.D.Fett@seagate.com</font>
<br>
<br>
<br>
<table width=100%>
<tr valign=top>
<td width=40%><font size=1 face="sans-serif"><b>Joost van Doremalen <dondervogeltj40@hotmail.com></b>
</font>
<br><font size=1 face="sans-serif">Sent by: wxpython-users-bounces@lists.wxwidgets.org</font>
<br><font size=1 face="sans-serif">No Phone Info Available</font>
<p><font size=1 face="sans-serif">07/14/2008 12:11 PM</font>
<table border>
<tr valign=top>
<td bgcolor=white>
<div align=center><font size=1 face="sans-serif">Please respond to<br>
wxpython-users@lists.wxwidgets.org</font></div></table>
<br>
<td width=59%>
<table width=100%>
<tr valign=top>
<td>
<div align=right><font size=1 face="sans-serif">To</font></div>
<td><font size=1 face="sans-serif"><wxpython-users@lists.wxwidgets.org></font>
<tr valign=top>
<td>
<div align=right><font size=1 face="sans-serif">cc</font></div>
<td>
<tr valign=top>
<td>
<div align=right><font size=1 face="sans-serif">Subject</font></div>
<td><font size=1 face="sans-serif">[wxpython-users] button labels with
different font colors and styles</font></table>
<br>
<table>
<tr valign=top>
<td>
<td></table>
<br></table>
<br>
<br>
<br><tt><font size=2><br>
<br>
Hi all,<br>
<br>
I want to put a text label on a button, but the label has different colors
and styles:<br>
some words are marked blue and are bold, other words are formatted normally.<br>
<br>
I haven't found a way to do this. Is this possible? if yes, how can I achieve
this?<br>
<br>
Regards,<br>
Joost<br>
_________________________________________________________________<br>
Use video conversation to talk face-to-face with Windows Live Messenger.<br>
http://www.windowslive.com/messenger/connect_your_way.html?ocid=TXT_TAGLM_WL_Refresh_messenger_video_072008_______________________________________________<br>
wxpython-users mailing list<br>
wxpython-users@lists.wxwidgets.org<br>
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users<br>
</font></tt>
<br>_______________________________________________
wxpython-users mailing list
[email protected]
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users