wxpython应用程序在较低分辨率

时间:2016-04-13 15:42:47

标签: user-interface wxpython resolution maximize sizer

晚上好/早上好,

我一直在1920x1080显示器上进行深入研究。我最大限度地设置了适合我的显示器的所有东西。我有一些问题,我认为这与我设置sizer的方式有关。

首先,当我减小屏幕的实际尺寸时,窗口内容不随之减小,而是从右侧切断。因此,较小的屏幕意味着内容的一半,而不是内容大小的一半。

当我调整分辨率时,这个问题也继续存在。对于较低的分辨率,我只能获得实际适合屏幕的一半内容。我不知道我应该如何设置我的sizer来解决这个问题,所以这里简要介绍一下我现在的方式:

import wx

class simpleapp_wx(wx.Frame):
    def __init__(self,parent,id,title):
        wx.Frame.__init__(self,parent,id,title,(-1,-1))
        self.parent = parent
        self.initialize()

    """ Create All of the pieces for the GUI """
    def initialize(self):
        sizer = wx.GridBagSizer()
        panel = wx.Panel(self)

        # Handles the creation of all of the buttons
        def make_button(text, starty, startx, height, width):
            button = wx.Button(self, -1, text)
            sizer.Add(button, (starty, startx), (height, width), wx.EXPAND)
            return button

        # Handles the c reation of all of the static text labels
        def make_label(text, starty, startx, height, width):
            self.label = wx.StaticText(self, -1, text, wx.DefaultPosition, wx.DefaultSize)
            sizer.Add(self.label, (starty, startx), (height, width), wx.EXPAND)
            return self.label

        # Create all of the labels for each slot and buttons
        for i in range(0, 4):
            # all the labels
            make_label('Voltage', 7, i*5, 1, 1)
            make_label('Current', 8, i*5, 1, 1)
            make_label('Power', 9, i*5, 1, 1)
            make_label('Rail 1', 6, (i*5)+1, 1, 1)
            make_label('Rail 2', 6, (i*5)+2, 1, 1)
            make_label('Rail 3', 6, (i*5)+3, 1, 1)
            make_label('Total Power', 6, (i*5)+4, 1, 1)
            make_label('Status:', 14, (i*5), 1, 1)
            # Global Rail commands for all 4 slots
            make_button("Margin Low", 1, (i*5)+2, 1, 1)
            make_button("Margin High", 1, (i*5)+3, 1, 1)
            make_button("Margin Off", 1, (i*5)+4, 1, 1)
            # Rail 1 for all 4 slots
            make_button("Margin High", 11, (i*5)+1, 1, 1)
            make_button("Margin Low", 12, (i*5)+1, 1, 1)
            make_button("Margin Off",  13, (i*5)+1, 1, 1)
            # Rail 2 for all 4 slots
            make_button("Margin High",  11, (i*5)+2, 1, 1)
            make_button("Margin Low", 12, (i*5)+2, 1, 1)
            make_button("Margin Off", 13, (i*5)+2, 1, 1)
            # Rail 3 for all 4 slots
            make_button("Margin High",  11, (i*5)+3, 1, 1)
            make_button("Margin Low",  12, (i*5)+3, 1, 1)
            make_button("Margin Off",  13, (i*5)+3, 1, 1)
            # Create the Configure buttons for each slot (only needs to run three times so needs if statement
            if i < 3:
                # Make the Configure buttons for Slot 1
                make_button("Configure",  10, i+1, 1 ,1)
                # Make the Configure buttons for Slot 2
                make_button("Configure",  10, i+6, 1, 1)
                # Make the Configure buttons for Slot 3
                make_button("Configure",  10, i+11, 1, 1)
                # Make the Configure buttons for Slot 4
                make_button("Configure",  10, i+16, 1, 1)

        self.SetSizerAndFit(sizer)
        self.SetSizeHints(-1,-1)
        self.Show(True)
        self.Maximize(True)

if __name__ == "__main__":
    app = wx.App()
    frame = simpleapp_wx(None,-1,'Add-in Card GUI')
    app.MainLoop()

我一直在阅读,我在某处读到了将gridbagsizer放在面板中的情况,这应该可行,所以我修改后的标题更接近:

    sizer = wx.GridBagSizer()
    panel = wx.Panel(self)

    panel.SetSizer(sizer)
    panel.Fit()
    self.Fit()
    self.Show(True)
    self.Maximize(True)

这也没有改变任何事情。我已经尝试将SetSizeHints设置为特定的分辨率,但这也不起作用。

那么,导致这个问题的原因是什么?我觉得它与我有关,只需使用一个sizer就可以获得所有内容。如果是这种情况,我最简单的方法是在不必完全重新构建新的sizer并分解内容的情况下解决这个问题?

1 个答案:

答案 0 :(得分:0)

You need to mark the columns and rows of the sizer as growable:

...
for i in range(0, 20):
    sizer.AddGrowableCol(i, 1)
for i in range(0, 15):
    sizer.AddGrowableRow(i, 1)

self.SetSizerAndFit(sizer)
...

works on your example. Now, it still won't shrink down very far, because you've got a lot of widgets, and they've all got minimum sizes, but it will pack in at least a bit tighter. (And expand to occupy more space, if available.)

For at least wxPython>=3, you need to make sure that you only try to make a row or column growable if it exists.

相关问题