Vladimir Keleshev
Vladimir Keleshev

Reputation: 14315

wxPython inherit font

How to avoid writing for each label:

static_text.SetFont(wx.Font(...))
static_text.SetForegroundColour(wx.Colour(...))

and instead inherit the font from parent element or something?

Upvotes: 0

Views: 428

Answers (2)

joaquin
joaquin

Reputation: 85693

If you change the font of the parent container you get that font for all the widgets on it. For example changing the font for the Frame instance, font gets changed in the static text and the checkbox without the need to set them separately:

enter image description here

Afaik if you want to modify existing code you can not access to write the SetFont line, then you need these classes to have been written with that in mind. The obvious thing would be to have the Font set in a method outside __init__ in the parent class in order to overwrite it in your class that will be inheriting from the restricted-access class

Upvotes: 2

Vader
Vader

Reputation: 3883

Try something like that:

class Label(wx.StaticText):
    def __init__(self, *args, **kwargs):
        wx.StaticText.__init__(self, *args, **kwargs)
        self.SetFont(wx.Font(...))
        self.SetForegroundColour(wx.Colout(...))
...
static_text = Label(...)

Upvotes: 1

Related Questions