[출처 : http://withrobot.tistory.com/144]


앞서 소개한 방법은 라디오버튼을 만들고, 그리드 컨트롤을 사용하여 라디오 버튼을 배치하고 이를 다시 StaticBox로 감싸서 배치해야 하는 번거로움이 있었다. wxPython에서는 이와 같은 과정을 하나의 함수로 간단하게 설정할 수 있는 컨트롤을 추가로 제공하는데 이것이 바로 RadioBox() 이다.

RadioBox()를 사용하면 다음과 같이 소스가 매우 간결해 진다.

사용자 삽입 이미지

RadioBox를 이용하여 두 개의 라디오 버튼 그룹 생성



#!/usr/bin/env python

"""11-2 RadioBox """

# http://withrobot.tistory.com
# 2007.12.04

import wx

class Frame(wx.Frame):
    def __init__(self, parent=None, id=-1, title='RadioBox'):
        wx.Frame.__init__(self, parent, id, title, size=(300,300), pos=(100,100) )
        panel = wx.Panel(self)

        sampleList = ['zero', 'one', 'two', 'three', 'four', 'five',
                      'six', 'seven', 'eight']
        wx.RadioBox(panel, -1, "Group A", (10,10), wx.DefaultSize,sampleList,2,wx.RA_SPECIFY_COLS)
        wx.RadioBox(panel, -1, "", (10,150), wx.DefaultSize,sampleList,3,wx.RA_SPECIFY_COLS)        
         
class App(wx.App):
    def OnInit(self):
        self.frame = Frame()
        self.frame.Show()
        return True

def main():
    app = App()
    app.MainLoop()

if __name__ == '__main__':
    main()

+ Recent posts