WxPython사용기 2.

Getting Started 셈플코드로 연습.
1. "Hellow World."
import wx
app = wx.PySimpleApp()
frame = wx.Frame(None, -1, "Hello World")
frame.Show(1)
app.MainLoop()

- 위 소스의 문제 pythonWin에서 두번이상 안돌아감.(원인은 대충 알것 같으나, 확인은 안해봄. 이 밖에 정식 소스는 2번이상 잘 돌아감.)
- 참고 : http://wxwidgets.org/manuals/2.5.3/wx_wxframe.html#wxframe

2. 작동하는 셈플
import wx
class MainWindow(wx.Frame):
""" We simply derive a new class of Frame. """
def __init__(self,parent,id, title):
wx.Frame.__init__(self,parent,wx.ID_ANY,title,size=(200,100),style=wx.DEFAULT_FRAME_STYLE|wx.NO_FULL_REPAINT_ON_RESIZE)
self.control = wx.TextCtrl(self,1,style=wx.TE_MULTILINE)
self.Show(True)

app = wx.PySimpleApp()

frame=MainWindow(None,-1,'Small editor')
app.MainLoop()

- 텍스트 컨트롤이 추가된 작은 메모장

3. 메뉴가 추가된
import os
from wxPython.wx import *
ID_ABOUT=101 #1. 이벤트 아이디를 생성.
class MainWindow(wxFrame):
def __init__(self,parent,id,title):
wxFrame.__init__(self,parent,wxID_ANY, title, size = ( 200,100),
style=wxDEFAULT_FRAME_STYLE|
wxNO_FULL_REPAINT_ON_RESIZE)
self.control = wxTextCtrl(self, 1, style=wxTE_MULTILINE)
self.CreateStatusBar() # A StatusBar in the bottom of the window
# Setting up the menu.
filemenu= wxMenu()
filemenu.Append(ID_ABOUT, "&About"," Information about this program")
# Creating the menubar.
menuBar = wxMenuBar()
menuBar.Append(filemenu,"&File") # Adding the "filemenu" to the MenuBar
self.SetMenuBar(menuBar) # Adding the MenuBar to the Frame content.
EVT_MENU(self, ID_ABOUT, self.OnAbout) # 2. 이벤트와 메써드를 연결. attach the menu-event ID_ABOUT to the OnAbout
self.Show(true)

# 3. 이벤트와 연결된 메써드
def OnAbout(self,e):
d= wxMessageDialog( self, " A sample editor \n"
" in wxPython","About Sample Editor", wxOK)
# Create a message dialog box
d.ShowModal() # Shows it
d.Destroy() # finally destroy it when finished.

app = wxPySimpleApp()
frame = MainWindow(None, -1, "Sample editor")
app.MainLoop()

- 이벤트 추가 절차
1. 이벤트 아이디를 생성.
2. 이벤트와 메써드를 연결.
3. 이벤트와 연결된 메써드를 작성.

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

Posted by 나현재

2005/06/27 14:53 2005/06/27 14:53
Response
2 Trackbacks , No Comment
RSS :
http://j.finfra.com/tt/rss/response/254

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

Trackbacks List

  1. WxPython사용기 1.

    Tracked from NaHyunJae build a castle in real, and fly! - 나현재 2005/06/28 13:31 Delete

    개요 WxPython은 python을 위한 Gui 작성 모듈로 현재 2.6.1.0버전 까지 나왔다. 관련 사이트 http://www.wxpython.org/ down : http://www.wxpython.org/download.php 시작 다운 받아 설치 하고, 샘플을 실행시켜 본다.(

  2. WxPython사용기 3.

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

    몇가지 셈플소스. 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):..

« Previous : 1 : ... 51 : 52 : 53 : 54 : 55 : 56 : 57 : 58 : 59 : ... 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