wxpython flexgridSizer按钮右下角

2024-09-27 23:25:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我想把“Enregister”按钮放在右下角: 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)

我搞不懂为什么按钮不在拐角处。在

你能帮帮我吗?在


Tags: the代码inselfaddhereall按钮
1条回答
网友
1楼 · 发布于 2024-09-27 23:25:58

声明的you 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

相关问题 更多 >

    热门问题