본문 바로가기

Language/Python

[wxPython] wx.GridBagSizer를 이용한 wx.Button 정렬하기

본 내용의 출처는 이글루 블로그의 '하린아빠' 라는 네임을 쓰시는 분의 블로그입니다.

[출처] - http://pythondev.egloos.com/103019


행여나 이글루 블로그가 없어지면 참고할 곳이 사라지기에 주인장님께 댓글을 남기고 퍼 옵니다.


[wxPython] wx.GridBagSizer를 이용한 wx.Button 정렬하기


#!/usr/bin/python
# -*- coding: cp949 -*-
# layout.py

import wx

class MyFrame(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition)

        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,7), wx.EXPAND)
        sizer.Add(wx.Button(self,-1, "Button"), (6, 6), (3,3), wx.EXPAND)
        sizer.Add(wx.Button(self,-1, "Button"), (3, 0), (1,1), wx.ALIGN_CENTER)
        sizer.Add(wx.Button(self,-1, "Button"), (4, 0), (1,1), wx.ALIGN_LEFT)
        sizer.Add(wx.Button(self,-1, "Button"), (5, 0), (1,1), wx.ALIGN_RIGHT)
        sizer.AddGrowableRow(6)
        sizer.AddGrowableCol(6)

        # Frame에 GridBagSizer 셋팅
        self.SetSizerAndFit(sizer)
        self.Centre()

class MyApp(wx.App):
    def OnInit(self):
        frame = MyFrame(None, -1, 'calculator.py')
        frame.Show(True)
        self.SetTopWindow(frame)
        return True


app = wx.App()
mainapp = MyApp(app)
mainapp.MainLoop()        

[실행 화면]