wxPython在网格小部件底部和网格边界内不希望有的空间

问题描述

Python 3.8 x64 | Windows 10 x64 | wxPython版本4.1.0

一直到处寻找答案,无济于事。我创建了一个简单的wx.grid.Grid()小部件,并在网格周围添加了边框。问题在于,网格小部件与网格底部间的边界之间包含空白区域。我没有描述使用大小调整器添加的边框外部周围的空间。我选择的边框是wx.BORDER_THEME,我不想更改它,因为我的GUI的其余部分都使用了相同的边框。我确实将行大小设置为20,但是无论将行大小更改为什么,问题仍然存在。

我在下面提供了一个最小的,可重复的代码示例。乍一看似乎很多,但实际上不是,而且非常基础。

此外,还附有一张图片,说明了我上面试图描述的内容。所附照片的底线是边框,上线是网格。


最小代码示例:

import wx
import wx.grid


class MyGrid(wx.Frame):
    def __init__(self):
        super().__init__(parent=None,title='Grid With Undesirable Space',size=(650,300))
        self.SetMinSize(self.GetSize())  # set min size of frame
        self.rows,self.columns = 1,4

        panel = wx.Panel(self)

        self.grid = wx.grid.Grid(panel,style=wx.BORDER_THEME)
        self.grid.CreateGrid(self.rows,self.columns)
        self.grid.ShowScrollbars(wx.SHOW_SB_NEVER,wx.SHOW_SB_NEVER)  # remove scroll bars

        # set all cells in first row Read Only
        attr = wx.grid.GridCellAttr()
        attr.SetReadOnly(True)
        self.grid.SetRowAttr(0,attr)

        self.grid.HideRowLabels()
        self.grid.SetRowSize(0,20)
        self.grid.disableDragRowSize()

        self.grid.SetColLabelSize(20)

        self.grid.SetColLabelValue(0,'Nintendo')
        self.grid.SetColLabelValue(1,'Super Nintendo')
        self.grid.SetColLabelValue(2,'Nintendo 64')
        self.grid.SetColLabelValue(3,'Nintendo GameCube')

        v_Box = wx.BoxSizer(wx.VERTICAL)
        v_Box.Add(self.grid,proportion=0,flag=wx.ALL | wx.EXPAND,border=10)
        panel.SetSizer(v_Box)
        self.Layout()

        # set the initial size of columns based on initial frame size
        self.resize_with_frame()

        self.grid.Bind(wx.EVT_SIZE,lambda event: self.resize_with_frame())

    def resize_with_frame(self):
        """Dynamically resize columns with the size of the frame."""
        width,height = self.GetClientSize()
        for column in range(self.columns):
            self.grid.SetColSize(column,(width - 20) / self.columns)  # width - 20 for border of 10 on both sides
            

if __name__ == "__main__":
    app = wx.App()
    gui = MyGrid()
    gui.Show()
    app.MainLoop()

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)