1. "Hellow World."
import wx
app = wx.PySimpleApp()
frame = wx.Frame(None, -1, "Hello World")
frame.Show(1)
app.MainLoop()
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()
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()
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. 이벤트와 연결된 메써드를 작성.
Copyright Finfra(http://www.finfra.com) All Rights Reserved
Posted by 나현재




