본문 바로가기
Programming/Python_Etc

wxpython GridBagSizer 예제

by Wilkyway 2020. 6. 21.
반응형

쉽게 레이아웃을 구성할 수 있는 GridBagSizer 예제입니다.

import wx

class MyFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, parent=None, title="GridBagSizer Example")
        sizer = wx.GridBagSizer(9, 9)
        #GridBagSizer.add(아이템, 가상그리드 위치(행, 열), 크기(높이, 넓이), 정렬상수, 여백)
        sizer.Add(wx.Button(self, -1, "Button"), (0, 0), wx.DefaultSpan, wx.ALL, 0)
        sizer.Add(wx.Button(self, -1, "Button"), (1, 1), (1, 1), wx.EXPAND)
        sizer.Add(wx.Button(self, -1, "Button"), (2, 2), (3, 3), wx.EXPAND)
        sizer.Add(wx.Button(self, -1, "Button"), (3, 0), (1, 1), wx.EXPAND)
        sizer.Add(wx.Button(self, -1, "Button"), (4, 0), (1, 1), wx.EXPAND)
        sizer.Add(wx.Button(self, -1, "Button"), (5, 2), (3, 3), wx.EXPAND)
        #sizer.AddGrowableRow(5)
        #sizer.AddGrowableCol(6)

        #Frmae에 GridBagSizer세팅
        self.SetSizerAndFit(sizer)
        self.Centre()

if __name__ == "__main__":
    app = wx.App()
    frm = MyFrame()
    frm.Show()
    app.MainLoop()

반응형

댓글