471,348 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Changing font style/size for overall wx.python GUI look

46
Hey guys

I have had a bit of a hunt around on google to try find out how to change the overall default font style/size for a wx.python app - but not had any luck.

Does anyone have any idea if it is possible?

All I really want to do is make the wx.StaticText, wx.CheckBox, wx.TextCtrl & wx.Button fonts smaller in my GUI app

Thanks if anyone can give me some pointers!

Cheers

Adam
Jul 11 '07 #1
4 13399
bartonc
6,596 Expert 4TB
Hey guys

I have had a bit of a hunt around on google to try find out how to change the overall default font style/size for a wx.python app - but not had any luck.

Does anyone have any idea if it is possible?

All I really want to do is make the wx.StaticText, wx.CheckBox, wx.TextCtrl & wx.Button fonts smaller in my GUI app

Thanks if anyone can give me some pointers!

Cheers

Adam
One word: inheritance! Set the font size for a panel and all the widgets on that panel get that font size by default. Same thing with any parent of any widget. Since the app is not a window, nobody inherits attributes from it.

I'm pretty sure, but I'll double check that.
Jul 11 '07 #2
bartonc
6,596 Expert 4TB
One word: inheritance! Set the font size for a panel and all the widgets on that panel get that font size by default. Same thing with any parent of any widget. Since the app is not a window, nobody inherits attributes from it.

I'm pretty sure, but I'll double check that.
wxWindow is the lowes object that I could find that has a font attribute. The most interesting thing that I stumbled across was this:
wxWindow::InheritAttributes
void InheritAttributes()

This function is (or should be, in case of custom controls) called during window creation to intelligently set up the window visual attributes, that is the font and the foreground and background colours.

By "intelligently'' the following is meant: by default, all windows use their own default attributes. However if some of the parents attributes are explicitly (that is, using SetFont and not SetOwnFont) changed and if the corresponding attribute hadn't been explicitly set for this window itself, then this window takes the same value as used by the parent. In addition, if the window overrides ShouldInheritColours to return false, the colours will not be changed no matter what and only the font might.

This rather complicated logic is necessary in order to accommodate the different usage scenarios. The most common one is when all default attributes are used and in this case, nothing should be inherited as in modern GUIs different controls use different fonts (and colours) than their siblings so they can't inherit the same value from the parent. However it was also deemed desirable to allow to simply change the attributes of all children at once by just changing the font or colour of their common parent, hence in this case we do inherit the parents attributes.
Jul 11 '07 #3
ateale
46
Thanks BartonC !
I had a look and tried to use:
font = wx.Font(10, wx.FONTFAMILY_MODERN, wx.NORMAL, wx.BOLD)
wx.Window.SetFont(self, font)

but it doesn't change anything

I don't think i really understand the wx.window and inheritance thing. I read about inheritance in the doc, but I don't understand how to apply it to my script

i just realised I am using wx.Frame not wx.Window - guess this is the reason?

Any ideas?

Thanks!

Adam
Jul 13 '07 #4
bartonc
6,596 Expert 4TB
Thanks BartonC !
I had a look and tried to use:
panel.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD))

but it doesn't change anything

I don't think i really understand the wx.window and inheritance thing. I read about inheritance in the doc, but I don't understand how to apply it to my script

Any ideas?

Thanks!

Adam
Yep. When you're sticking down your widgets in a frame, you need to watch who the parent is. I'll use a subclass of dialog as an example:
Expand|Select|Wrap|Line Numbers
  1. class SegmentDialog(wx.Dialog):   # The parent of widgets that get self as their parent
  2.     def _init_ctrls(self, prnt):
  3.         # generated method, don't edit
  4.         wx.Dialog.__init__(self, id=wxID_SEGMENTDIALOG, name='SegmentDialog', parent=prnt,
  5.                 pos=wx.Point(8, 8), size=wx.Size(1008, 724), style=wx.DEFAULT_DIALOG_STYLE,
  6.                 title='Station Capture - HETAP Pro 2.0')
  7.         self.SetFont(wx.Font(18, wx.SWISS, wx.NORMAL, wx.NORMAL, False,'MS Shell Dlg 2'))
  8. # the panel would get that font, but gets its own, instead.
  9.  
  10.         self.panel1 = wx.Panel(id=wxID_SEGMENTDIALOGPANEL1, name='panel1', parent=self,   # Here is the panel's parent #
  11.                 pos=wx.Point(0, 0), size=wx.Size(1008, 696), style=wx.TAB_TRAVERSAL)
  12.         self.panel1.SetBackgroundColour(wx.Colour(232, 232, 232))
  13.         self.panel1.SetToolTipString('')
  14.         self.panel1.SetFont(wx.Font(16, wx.SWISS, wx.NORMAL, wx.BOLD, False,'MS Shell Dlg 2'))
  15. # widgets get the panel as the parent
  16.  
  17.         self.staticLine1 = wx.StaticLine(id=wxID_SEGMENTDIALOGSTATICLINE1, name='staticLine1',
  18.                 parent=self.panel1, pos=wx.Point(16, 185), size=wx.Size(795, 3), style=0)
  19. # and, so, get that font
  20.  
  21.     def __init__(self, parent, dbDialog, publisher):
  22.         self._init_ctrls(parent)
Hope that's clear.
Jul 13 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

131 posts views Thread by Peter Foti | last post: by
4 posts views Thread by tshad | last post: by
30 posts views Thread by Takehiko Abe | last post: by
1 post views Thread by Ronak mishra | last post: by

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.