Question

Im looking for a way to present a flexible font, that will increase and decrease in size according to to the size of the screen resolution. I want to be able to do this without the HTML window class. Is there a way? I thought I've done quite a bit of googling without success.

EDIT This seems a good question, I changed the title to reflect closer what I was looking for.

EDIT

So now I've realized that the regular pixel sizes will scale in the way I mentioned already - but I saw this the other day and realized it might be helpful if someone wanted to use CSS with their wxPython Apps - its a library that allows you to 'skin' your application and I can think of a dozen neat ways to use it already - here is a link in lieu of a more well thought out question :)

link text

Was it helpful?

Solution

Maybe something like this? You can scale any wx.Window in this way. Not sure if this is exactly what you mean though.

import wx

def scale(widget, percentage):
    font = widget.GetFont()
    font.SetPointSize(int(font.GetPointSize() * percentage / 100.0))
    widget.SetFont(font)

class Frame(wx.Frame):
    def __init__(self):
        super(Frame, self).__init__(None, -1, 'Scaling Fonts')
        panel = wx.Panel(self, -1)
        sizer = wx.BoxSizer(wx.VERTICAL)
        for i in range(50, 201, 25):
            widget = wx.StaticText(panel, -1, 'Scale Factor = %d' % i)
            scale(widget, i)
            sizer.Add(widget, 0, wx.ALL, 5)
        panel.SetSizer(sizer)

if __name__ == '__main__':
    app = wx.PySimpleApp()
    frame = Frame()
    frame.Show()
    app.MainLoop()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top