这是我的代码:
sizer = wx.FlexGridSizer(10, 6, 10, 10)
# here i had all the other stuff an put it in the sizer
# self refere to a wx.panel
# SPACE
for v in range(0, 40):
sizer.Add(10,10,wx.EXPAND)
btn = wx.Button(self, wx.ID_ANY, "Enregistrer")
btn.Bind(wx.EVT_BUTTON, self.save)
sizer.Add(btn, 2, wx.ALIGN_BOTTOM|wx.ALIGN_RIGHT)
self.SetSizer(sizer)
我无法弄清楚为什么按钮没有滑到角落。
你能帮我吗?
答案 0 :(得分:1)
您声明的FlexGridSizer
大小(10x6)与要放入其中的项目数(40 + 1按钮)不匹配。
一点点更改代码:
#!/usr/bin/env python
import wx
class MyFrame(wx.Frame):
def __init__(self, parent, ID, title):
wx.Frame.__init__(self, parent, ID, title, wx.DefaultPosition)
sizer = wx.FlexGridSizer(10, 6, 10, 10)
# here i had all the other stuff an put it in the sizer
# self refere to a wx.panel
# SPACE
v=[]
for i in range(0,59):
v.append(wx.StaticText(self,-1,"......"+str(i)))
for i in v:
sizer.Add(i,1,wx.EXPAND)
btn = wx.Button(self, wx.ID_ANY, "Enregistrer")
#btn.Bind(wx.EVT_BUTTON, self.save)
sizer.Add(btn,0,wx.EXPAND|wx.ALIGN_RIGHT)
self.SetSizer(sizer)
class MyApp(wx.App):
def OnInit(self):
frame = MyFrame(None, -1, "FlexGridSizer")
frame.Show(True)
self.SetTopWindow(frame)
return True
if __name__ == "__main__":
app = MyApp(0)
app.MainLoop()
但是,如果要在屏幕的右下角分别单击按钮,则可能要添加多个定尺寸器或完全选择其他定尺寸器。例如GridSizer
或GridBagSizer