본문 바로가기

Language/Python

[wxPython] 다이얼로그(Dialog) 만들기

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

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

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



[wxPython] 다이얼로그(Dialog) 만들기



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


import wx

class MyDialog(wx.Dialog):
    def __init__(self, parent, id, title):
        wx.Dialog.__init__(self, parent, id, title, size=(350,300))
        # 다이얼 로그 구성 처리
        sizer =  self.CreateTextSizer('My Buttons')
        sizer.Add(wx.Button(self, -1, 'Button'), 0, wx.ALL, 5)
        sizer.Add(wx.Button(self, -1, 'Button'), 0, wx.ALL, 5)
        sizer.Add(wx.Button(self, -1, 'Button'), 0, wx.ALL, 5)
        sizer.Add(wx.Button(self, -1, 'Button'), 0, wx.ALL|wx.ALIGN_CENTER, 5)
        sizer.Add(wx.Button(self, -1, 'Button'), 0, wx.ALL|wx.EXPAND, 5)
        self.SetSizer(sizer)

class MyFrame(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, size=(550,500))

        panel = wx.Panel(self, -1)
        wx.Button(panel, 1, 'Show Custom Dialog', (100,100))
        # 버튼 이벤트 연결
        self.Bind (wx.EVT_BUTTON, self.OnShowCustomDialog, id=1)

    # 버튼 이벤트 처리 함수
    def OnShowCustomDialog(self, event):
        # 다이얼로그 생성
        dia = MyDialog(self, -1, 'buttons')
        # 모달 처리
        dia.ShowModal()
        # 다이얼로그 파괴하기
        dia.Destroy()


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


        return True

app = MyApp(0)
app.MainLoop()

[실행 화면]