1. 응용프로그램 기본
import wx
app = wx.App()
frame = wx.Frame(None, -1, "Hello World")
frame.Show(1)
app.SetTopWindow(frame)
app.MainLoop()
app = wx.App()
frame = wx.Frame(None, -1, "Hello World")
frame.Show(1)
app.SetTopWindow(frame)
app.MainLoop()
import wx
class Frame(wx.Frame):
pass
class App(wx.App):
def OnInit(self):
self.frame=Frame(parent=None, id=-1, title="Test...")
self.frame.Show()
self.SetTopWindow(self.frame)
return True
if __name__ == '__main__':
app = App()
app.MainLoop()
class Frame(wx.Frame):
pass
class App(wx.App):
def OnInit(self):
self.frame=Frame(parent=None, id=-1, title="Test...")
self.frame.Show()
self.SetTopWindow(self.frame)
return True
if __name__ == '__main__':
app = App()
app.MainLoop()
-아래와 위는 같은 코드이나 클레스를 사용해서 실현해야 확장성 높음.
2. textBox, button사용법.
# -*- coding: utf-8 -*-
import wx
[wxID_FRAME1, wxID_FRAME1BUTTON1, wxID_FRAME1TEXTCTRL1, wxID_FRAME1BUTTON2
] = [wx.NewId() for _init_ctrls in range(4)]
class t1Frame1(wx.Frame):
def _init_ctrls(self, prnt):
# generated method, don't edit
wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
pos=wx.Point(448, 310), size=wx.Size(400, 250),
style=wx.DEFAULT_FRAME_STYLE, title='Frame1')
self.SetClientSize(wx.Size(392, 223))
self.textCtrl1 = wx.TextCtrl(id=wxID_FRAME1TEXTCTRL1, name='textCtrl1',
parent=self, pos=wx.Point(128, 56), size=wx.Size(100, 22),
style=0, value='textCtrl1')
self.button1 = wx.Button(id=wxID_FRAME1BUTTON1, label='텍스트에 -----넣기',
name='button1', parent=self, pos=wx.Point(136, 88),
size=wx.Size(175, 24), style=0)
self.button1.Bind(wx.EVT_BUTTON, self.OnButton1Button,
id=wxID_FRAME1BUTTON1)
self.button2 = wx.Button(id=wxID_FRAME1BUTTON2, label='텍스트값 메세지박스로 보여주기',
name='button2', parent=self, pos=wx.Point(136, 130),
size=wx.Size(175, 24), style=0)
self.button2.Bind(wx.EVT_BUTTON, self.OnButton2Button,
id=wxID_FRAME1BUTTON2)
def __init__(self, parent):
self._init_ctrls(parent)
def OnButton1Button(self, event):
self.textCtrl1.SetValue("---------")
def OnButton2Button(self, event):
dlg = wx.MessageDialog(self, self.textCtrl1.GetValue(),
'텍스트 박스의 값',
wx.OK | wx.ICON_INFORMATION
#wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_INFORMATION
)
dlg.ShowModal()
dlg.Destroy()
class BoaApp(wx.App):
def OnInit(self):
wx.InitAllImageHandlers()
self.main = t1Frame1(None)
self.main.Show()
self.SetTopWindow(self.main)
return True
if __name__ == '__main__':
app = BoaApp()
app.MainLoop()
import wx
[wxID_FRAME1, wxID_FRAME1BUTTON1, wxID_FRAME1TEXTCTRL1, wxID_FRAME1BUTTON2
] = [wx.NewId() for _init_ctrls in range(4)]
class t1Frame1(wx.Frame):
def _init_ctrls(self, prnt):
# generated method, don't edit
wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
pos=wx.Point(448, 310), size=wx.Size(400, 250),
style=wx.DEFAULT_FRAME_STYLE, title='Frame1')
self.SetClientSize(wx.Size(392, 223))
self.textCtrl1 = wx.TextCtrl(id=wxID_FRAME1TEXTCTRL1, name='textCtrl1',
parent=self, pos=wx.Point(128, 56), size=wx.Size(100, 22),
style=0, value='textCtrl1')
self.button1 = wx.Button(id=wxID_FRAME1BUTTON1, label='텍스트에 -----넣기',
name='button1', parent=self, pos=wx.Point(136, 88),
size=wx.Size(175, 24), style=0)
self.button1.Bind(wx.EVT_BUTTON, self.OnButton1Button,
id=wxID_FRAME1BUTTON1)
self.button2 = wx.Button(id=wxID_FRAME1BUTTON2, label='텍스트값 메세지박스로 보여주기',
name='button2', parent=self, pos=wx.Point(136, 130),
size=wx.Size(175, 24), style=0)
self.button2.Bind(wx.EVT_BUTTON, self.OnButton2Button,
id=wxID_FRAME1BUTTON2)
def __init__(self, parent):
self._init_ctrls(parent)
def OnButton1Button(self, event):
self.textCtrl1.SetValue("---------")
def OnButton2Button(self, event):
dlg = wx.MessageDialog(self, self.textCtrl1.GetValue(),
'텍스트 박스의 값',
wx.OK | wx.ICON_INFORMATION
#wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_INFORMATION
)
dlg.ShowModal()
dlg.Destroy()
class BoaApp(wx.App):
def OnInit(self):
wx.InitAllImageHandlers()
self.main = t1Frame1(None)
self.main.Show()
self.SetTopWindow(self.main)
return True
if __name__ == '__main__':
app = BoaApp()
app.MainLoop()
- 특별한 것은 없음. 소스가 좀 길어짐.
- 위 소스 1줄에 첨가된 것은 한글사용시 워닝 메세지를 표시하지 않기 위해 한글 코드셋을 지정함.
Copyright Finfra(http://www.finfra.com) All Rights Reserved
Posted by 나현재




