How to change font for entire wxPython application

Question:

I have a wxPython application (using 2.8), built with python 2.7.

Is there a way to change the font for the whole application ?
I mean, I would like to change font for any wx.StaticText, wx.Button, wx.Combo for every widget that shows “text”. Do I need to use the c++ wrapper (wxWidgets), if yes, how ?

Asked By: semantic-dev

||

Answers:

You should be able to use inheritance to set all the widgets to the same font, according to this thread:

The idea is to set the font on the top level parent, such as the wx.Panel. Then all the children will inherit that font.

This older thread mentions that you need to set the font BEFORE you create the widgets. If you need to change the font AFTER, then you’ll have to iterate over the child widgets, setting their font individually yourself. I would use parent.GetChildren() to get all or most of them.

Answered By: Mike Driscoll

Here is code to change the overall wxPython font.

wx.Frame.__init__(self, *args, **kwargs)
self.top_panel = wx.Panel(self)
self.top_panel.SetFont(wx.Font(14, wx.DEFAULT, wx.NORMAL, wx.NORMAL, False, 'Consolas'))
Answered By: JaeMann Yeh
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.