wxpython flexgridSizer按钮右下角

时间:2018-06-27 09:42:54

标签: python user-interface wxpython wxwidgets

我想在右下角放置“注册器”按钮: enter image description here

这是我的代码:

    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)

我无法弄清楚为什么按钮没有滑到角落。

你能帮我吗?

1 个答案:

答案 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()

我们得到这个: enter image description here

但是,如果要在屏幕的右下角分别单击按钮,则可能要添加多个定尺寸器或完全选择其他定尺寸器。例如GridSizerGridBagSizer