我正在制作一个小程序,使用wxpython和ogl库在python中绘制段。我已经创建并将画布添加到sizer中,但无法冻结画布的大小。
sizer = wx.BoxSizer(wx.VERTICAL)
canvas_sizer = wx.BoxSizer(wx.HORIZONTAL)
text_sizer = wx.BoxSizer(wx.HORIZONTAL)
stat = wx.StaticText(panel,-1,'position')
canvas = ogl.ShapeCanvas(panel)
diagram = ogl.Diagram()
canvas.SetDiagram(diagram)
diagram.SetCanvas(canvas)
canvas_sizer.Add(canvas,1,wx.GROW)
text_sizer.Add(stat,1,wx.ALL,5)
sizer.Add(canvas_sizer,1,wx.GROW)
sizer.Add(text_sizer)
self.SetSizer(sizer)
sizer.Fit(self)
上面的代码是我实际代码的一部分。请建议如何使画布大小固定
答案 0 :(得分:1)
您必须将插槽必须占用的比例设置为0,并在必要时为内容提供最小尺寸:
sizer = wx.BoxSizer(wx.VERTICAL)
text_sizer = wx.BoxSizer(wx.HORIZONTAL)
canvas_sizer = wx.BoxSizer(wx.HORIZONTAL)
stat = wx.StaticText(self, -1, "position")
# for testing I used a panel instead of your ogl object
canvas = wx.Panel(self, -1)
canvas.SetMinSize((-1, 70)) # Needed here to give a min size to panel,
# otherwise the panel would not be seen.
# The sizer will occupy the minimal
# to hold its contents.
canvas_sizer.Add(canvas, 1, wx.EXPAND, 0)
sizer.Add(canvas_sizer, 0, wx.EXPAND, 0) # <- note proportion 0 here
text_sizer.Add(stat, 1, wx.EXPAND, 0)
sizer.Add(text_sizer, 1, wx.EXPAND, 0)
self.SetSizer(sizer)
sizer.Fit(self)
self.Layout()