Erik343
Erik343

Reputation: 315

How to dynamically shrink or grow panel contents?

I have an issue with making my program panel fit into a low resolution. Like if I have a resolution of 800 x 600, and my panel is larger than that, so everything gets cut off, especially the buttons that are on the bottom of the screen.

So, I made a mock program as an example:

import wx

MAIN_FRAME_SIZE = (190, 150)

class MainFrame(wx.Frame):  

    def __init__(self):

        wx.Frame.__init__(self, None, id = -1, title = 'Hello, World!', size = MAIN_FRAME_SIZE)

        vertBox = wx.BoxSizer(wx.VERTICAL)   

        staticText = wx.StaticText(self, label = 'Hello, World!')

        vertBox.Add(staticText, 0, wx.ALL, 40)

        self.SetSizer(vertBox)       

if __name__ == '__main__':
    app = wx.App()
    frame = MainFrame()
    frame.Show(True)
    app.MainLoop()

So, then my question is how do I make the 'Hello, World!' text larger when the MainFrame gets larger, and how do I do the same when the MainFrame gets smaller?

Thanks.

Upvotes: 1

Views: 250

Answers (1)

VZ.
VZ.

Reputation: 22688

You can select your font size depending on the frame size using some heuristics or you can compute the length of your string using GetTextExtent() and find the font size for which it will be equal to what you want.

To do this dynamically when the frame is resized, you need to catch wxEVT_SIZE and change the font in its handler.

Upvotes: 1

Related Questions