user2451205
user2451205

Reputation: 11

How to mention height and Width in terms of percentage in size() in wxpython

How do I mention size(350,450) in terms of percentages in wxpython?

# -*- coding: utf-8 -*-
# gotoclass.py
import wx

class Example(wx.Frame):

    def __init__(self, parent, title):
        super(Example, self).__init__(parent, title=title, 
            size=(390, 350))
        self.InitUI()
        self.Centre()
        self.Show()     

    def InitUI(self):
        panel = wx.Panel(self)

        font = wx.SystemSettings_GetFont(wx.SYS_SYSTEM_FONT)
        font.SetPointSize(9)

        vbox = wx.BoxSizer(wx.VERTICAL)

        hbox1 = wx.BoxSizer(wx.HORIZONTAL)
        st1 = wx.StaticText(panel, label='Class Name')
        st1.SetFont(font)
        hbox1.Add(st1, flag=wx.RIGHT, border=8)
        tc = wx.TextCtrl(panel)
        hbox1.Add(tc, proportion=1)
        vbox.Add(hbox1, flag=wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP, border=10)

        vbox.Add((-1, 10))
        panel.SetSizer(vbox)

if __name__ == '__main__':
    app = wx.App()
    Example(None, title='Go To Class')
    app.MainLoop()

Upvotes: 0

Views: 1436

Answers (2)

Fenikso
Fenikso

Reputation: 9451

Get the screen resolution using wx.GetDisplaySize(). Compute the percentage in pixels. Set the size by self.SetSize() later, not in the constructor but before self.Show().

Upvotes: 1

Mike Driscoll
Mike Driscoll

Reputation: 33071

You can only specify the size of widgets in wxPython by pixel size. See http://wxpython.org/docs/api/wx.Size-class.html for more information. You cannot pass percentages to it. On the other hand, you can sort of do percentages with widgets inside sizers as sizers support the idea of proportion. But I don't believe that is what you really want.

Upvotes: 0

Related Questions