WxPython사용기 3.

몇가지 셈플소스.


1. 응용프로그램 기본
import wx
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()

-아래와 위는 같은 코드이나 클레스를 사용해서 실현해야 확장성 높음.


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()



- 특별한 것은 없음. 소스가 좀 길어짐.
- 위 소스 1줄에 첨가된 것은 한글사용시 워닝 메세지를 표시하지 않기 위해 한글 코드셋을 지정함.


Written by NaHyunJae(http://j.finfra.com)
Copyright Finfra(http://www.finfra.com) All Rights Reserved
이올린에 북마크하기(0) 이올린에 추천하기(0)

Posted by 나현재

2005/06/28 13:28 2005/06/28 13:28
Response
A trackback , No Comment
RSS :
http://j.finfra.com/tt/rss/response/255

Trackback URL : http://j.finfra.com/tt/trackback/255

Trackbacks List

  1. WxPython사용기 2.

    Tracked from NaHyunJae build a castle in real, and fly! - 나현재 2005/07/11 14:10 Delete

    Getting Started 셈플코드로 연습. 1. "Hellow World." import wx app = wx.PySimpleApp() frame = wx.Frame(None, -1, "Hello World") frame.Show(1) app.MainLoop() - 위 소스의 문제 pythonWin에서 두번이상 안돌아감.(원인은 대충 알것 ?

« Previous : 1 : ... 50 : 51 : 52 : 53 : 54 : 55 : 56 : 57 : 58 : ... 134 : Next »

블로그 이미지

Insufficient memory! So,Blog is my 2nd Brain!

- 나현재

Notices

Archives

Authors

  1. 나현재

Calendar

«   2012/05   »
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    

Site Stats

Total hits:
205602
Today:
16
Yesterday:
22