Hatena::ブログ(Diary)

sirocco の書いてもすぐに忘れるメモ

2014-07-26

Python: wxFormbuilder を使ってwxPythonアプリを作る。

| 12:48 |

PythonwxPythonGUIビルダwxFormBuilderを使って、テストアプリを作ってみました。

【環境】

f:id:sirocco:20140726124553j:image

「OK」ボタンを押すとテキストボックスに「OK」の文字が追加され、「CLEAR」ボタンを押すとテキストボックスをクリアします。

wxHaskellのときはXRCファイルを読み込んで、イベントは自分で設定していましたが、今回はwxFormbuilderでイベントを設定しました。

  • イベントの設定方法
    • Designerの「OK」のボタンを選択->EventのOnButtonClick欄に「OnButtunOK」。
    • Designerの「CLEAR」のボタンを選択->EventのOnButtonClick欄に「OnButtunCLEAR」。
  • wxTest.fbp : wxFormbuilder 自身の保存ファイル
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<wxFormBuilder_Project>
    <FileVersion major="1" minor="11" />
    <object class="Project" expanded="1">
        <property name="class_decoration"></property>
        <property name="code_generation">Python</property>
        <property name="disconnect_events">1</property>
        <property name="disconnect_mode">source_name</property>
        <property name="disconnect_php_events">0</property>
        <property name="disconnect_python_events">0</property>
        <property name="embedded_files_path">res</property>
        <property name="encoding">UTF-8</property>
        <property name="event_generation">connect</property>
        <property name="file">pytest</property>
        <property name="first_id">1000</property>
        <property name="help_provider">none</property>
        <property name="internationalize">0</property>
        <property name="name">pytest</property>
        <property name="namespace"></property>
        <property name="path">.</property>
        <property name="precompiled_header"></property>
        <property name="relative_path">1</property>
        <property name="skip_lua_events">1</property>
        <property name="skip_php_events">1</property>
        <property name="skip_python_events">1</property>
        <property name="ui_table">UI</property>
        <property name="use_enum">0</property>
        <property name="use_microsoft_bom">0</property>
        <object class="Frame" expanded="1">
            <property name="aui_managed">0</property>
            <property name="aui_manager_style">wxAUI_MGR_DEFAULT</property>
            <property name="bg"></property>
            <property name="center">wxBOTH</property>
            <property name="context_help"></property>
            <property name="context_menu">1</property>
            <property name="enabled">1</property>
            <property name="event_handler">impl_virtual</property>
            <property name="extra_style"></property>
            <property name="fg"></property>
            <property name="font"></property>
            <property name="hidden">0</property>
            <property name="id">wxID_ANY</property>
            <property name="maximum_size"></property>
            <property name="minimum_size"></property>
            <property name="name">fMain</property>
            <property name="pos"></property>
            <property name="size">500,300</property>
            <property name="style">wxDEFAULT_FRAME_STYLE</property>
            <property name="subclass"></property>
            <property name="title">wxFormbuilder TEST</property>
            <property name="tooltip"></property>
            <property name="window_extra_style"></property>
            <property name="window_name"></property>
            <property name="window_style">wxTAB_TRAVERSAL</property>
            <property name="xrc_skip_sizer">1</property>
            <event name="OnActivate"></event>
            <event name="OnActivateApp"></event>
            <event name="OnAuiFindManager"></event>
            <event name="OnAuiPaneButton"></event>
            <event name="OnAuiPaneClose"></event>
            <event name="OnAuiPaneMaximize"></event>
            <event name="OnAuiPaneRestore"></event>
            <event name="OnAuiRender"></event>
            <event name="OnChar"></event>
            <event name="OnClose"></event>
            <event name="OnEnterWindow"></event>
            <event name="OnEraseBackground"></event>
            <event name="OnHibernate"></event>
            <event name="OnIconize"></event>
            <event name="OnIdle"></event>
            <event name="OnKeyDown"></event>
            <event name="OnKeyUp"></event>
            <event name="OnKillFocus"></event>
            <event name="OnLeaveWindow"></event>
            <event name="OnLeftDClick"></event>
            <event name="OnLeftDown"></event>
            <event name="OnLeftUp"></event>
            <event name="OnMiddleDClick"></event>
            <event name="OnMiddleDown"></event>
            <event name="OnMiddleUp"></event>
            <event name="OnMotion"></event>
            <event name="OnMouseEvents"></event>
            <event name="OnMouseWheel"></event>
            <event name="OnPaint"></event>
            <event name="OnRightDClick"></event>
            <event name="OnRightDown"></event>
            <event name="OnRightUp"></event>
            <event name="OnSetFocus"></event>
            <event name="OnSize"></event>
            <event name="OnUpdateUI"></event>
            <object class="wxBoxSizer" expanded="1">
                <property name="minimum_size"></property>
                <property name="name">bSizer1</property>
                <property name="orient">wxVERTICAL</property>
                <property name="permission">none</property>
                <object class="sizeritem" expanded="1">
                    <property name="border">5</property>
                    <property name="flag">wxEXPAND</property>
                    <property name="proportion">1</property>
                    <object class="wxPanel" expanded="1">
                        <property name="BottomDockable">1</property>
                        <property name="LeftDockable">1</property>
                        <property name="RightDockable">1</property>
                        <property name="TopDockable">1</property>
                        <property name="aui_layer"></property>
                        <property name="aui_name"></property>
                        <property name="aui_position"></property>
                        <property name="aui_row"></property>
                        <property name="best_size"></property>
                        <property name="bg"></property>
                        <property name="caption"></property>
                        <property name="caption_visible">1</property>
                        <property name="center_pane">0</property>
                        <property name="close_button">1</property>
                        <property name="context_help"></property>
                        <property name="context_menu">1</property>
                        <property name="default_pane">0</property>
                        <property name="dock">Dock</property>
                        <property name="dock_fixed">0</property>
                        <property name="docking">Left</property>
                        <property name="enabled">1</property>
                        <property name="fg"></property>
                        <property name="floatable">1</property>
                        <property name="font"></property>
                        <property name="gripper">0</property>
                        <property name="hidden">0</property>
                        <property name="id">wxID_ANY</property>
                        <property name="max_size"></property>
                        <property name="maximize_button">0</property>
                        <property name="maximum_size"></property>
                        <property name="min_size"></property>
                        <property name="minimize_button">0</property>
                        <property name="minimum_size"></property>
                        <property name="moveable">1</property>
                        <property name="name">m_panel1</property>
                        <property name="pane_border">1</property>
                        <property name="pane_position"></property>
                        <property name="pane_size"></property>
                        <property name="permission">protected</property>
                        <property name="pin_button">1</property>
                        <property name="pos"></property>
                        <property name="resize">Resizable</property>
                        <property name="show">1</property>
                        <property name="size"></property>
                        <property name="subclass"></property>
                        <property name="toolbar_pane">0</property>
                        <property name="tooltip"></property>
                        <property name="window_extra_style"></property>
                        <property name="window_name"></property>
                        <property name="window_style">wxTAB_TRAVERSAL</property>
                        <event name="OnChar"></event>
                        <event name="OnEnterWindow"></event>
                        <event name="OnEraseBackground"></event>
                        <event name="OnKeyDown"></event>
                        <event name="OnKeyUp"></event>
                        <event name="OnKillFocus"></event>
                        <event name="OnLeaveWindow"></event>
                        <event name="OnLeftDClick"></event>
                        <event name="OnLeftDown"></event>
                        <event name="OnLeftUp"></event>
                        <event name="OnMiddleDClick"></event>
                        <event name="OnMiddleDown"></event>
                        <event name="OnMiddleUp"></event>
                        <event name="OnMotion"></event>
                        <event name="OnMouseEvents"></event>
                        <event name="OnMouseWheel"></event>
                        <event name="OnPaint"></event>
                        <event name="OnRightDClick"></event>
                        <event name="OnRightDown"></event>
                        <event name="OnRightUp"></event>
                        <event name="OnSetFocus"></event>
                        <event name="OnSize"></event>
                        <event name="OnUpdateUI"></event>
                        <object class="wxBoxSizer" expanded="1">
                            <property name="minimum_size"></property>
                            <property name="name">bSizer2</property>
                            <property name="orient">wxVERTICAL</property>
                            <property name="permission">none</property>
                            <object class="sizeritem" expanded="1">
                                <property name="border">5</property>
                                <property name="flag">wxALL|wxEXPAND</property>
                                <property name="proportion">1</property>
                                <object class="wxTextCtrl" expanded="1">
                                    <property name="BottomDockable">1</property>
                                    <property name="LeftDockable">1</property>
                                    <property name="RightDockable">1</property>
                                    <property name="TopDockable">1</property>
                                    <property name="aui_layer"></property>
                                    <property name="aui_name"></property>
                                    <property name="aui_position"></property>
                                    <property name="aui_row"></property>
                                    <property name="best_size"></property>
                                    <property name="bg"></property>
                                    <property name="caption"></property>
                                    <property name="caption_visible">1</property>
                                    <property name="center_pane">0</property>
                                    <property name="close_button">1</property>
                                    <property name="context_help"></property>
                                    <property name="context_menu">1</property>
                                    <property name="default_pane">0</property>
                                    <property name="dock">Dock</property>
                                    <property name="dock_fixed">0</property>
                                    <property name="docking">Left</property>
                                    <property name="enabled">1</property>
                                    <property name="fg"></property>
                                    <property name="floatable">1</property>
                                    <property name="font"></property>
                                    <property name="gripper">0</property>
                                    <property name="hidden">0</property>
                                    <property name="id">wxID_ANY</property>
                                    <property name="max_size"></property>
                                    <property name="maximize_button">0</property>
                                    <property name="maximum_size"></property>
                                    <property name="maxlength"></property>
                                    <property name="min_size"></property>
                                    <property name="minimize_button">0</property>
                                    <property name="minimum_size"></property>
                                    <property name="moveable">1</property>
                                    <property name="name">m_textCtrl1</property>
                                    <property name="pane_border">1</property>
                                    <property name="pane_position"></property>
                                    <property name="pane_size"></property>
                                    <property name="permission">protected</property>
                                    <property name="pin_button">1</property>
                                    <property name="pos"></property>
                                    <property name="resize">Resizable</property>
                                    <property name="show">1</property>
                                    <property name="size"></property>
                                    <property name="style"></property>
                                    <property name="subclass"></property>
                                    <property name="toolbar_pane">0</property>
                                    <property name="tooltip"></property>
                                    <property name="validator_data_type"></property>
                                    <property name="validator_style">wxFILTER_NONE</property>
                                    <property name="validator_type">wxDefaultValidator</property>
                                    <property name="validator_variable"></property>
                                    <property name="value"></property>
                                    <property name="window_extra_style"></property>
                                    <property name="window_name"></property>
                                    <property name="window_style"></property>
                                    <event name="OnChar"></event>
                                    <event name="OnEnterWindow"></event>
                                    <event name="OnEraseBackground"></event>
                                    <event name="OnKeyDown"></event>
                                    <event name="OnKeyUp"></event>
                                    <event name="OnKillFocus"></event>
                                    <event name="OnLeaveWindow"></event>
                                    <event name="OnLeftDClick"></event>
                                    <event name="OnLeftDown"></event>
                                    <event name="OnLeftUp"></event>
                                    <event name="OnMiddleDClick"></event>
                                    <event name="OnMiddleDown"></event>
                                    <event name="OnMiddleUp"></event>
                                    <event name="OnMotion"></event>
                                    <event name="OnMouseEvents"></event>
                                    <event name="OnMouseWheel"></event>
                                    <event name="OnPaint"></event>
                                    <event name="OnRightDClick"></event>
                                    <event name="OnRightDown"></event>
                                    <event name="OnRightUp"></event>
                                    <event name="OnSetFocus"></event>
                                    <event name="OnSize"></event>
                                    <event name="OnText"></event>
                                    <event name="OnTextEnter"></event>
                                    <event name="OnTextMaxLen"></event>
                                    <event name="OnTextURL"></event>
                                    <event name="OnUpdateUI"></event>
                                </object>
                            </object>
                            <object class="sizeritem" expanded="1">
                                <property name="border">5</property>
                                <property name="flag">wxALIGN_CENTER_HORIZONTAL</property>
                                <property name="proportion">0</property>
                                <object class="wxBoxSizer" expanded="1">
                                    <property name="minimum_size"></property>
                                    <property name="name">bSizer3</property>
                                    <property name="orient">wxHORIZONTAL</property>
                                    <property name="permission">none</property>
                                    <object class="sizeritem" expanded="1">
                                        <property name="border">5</property>
                                        <property name="flag"></property>
                                        <property name="proportion">0</property>
                                        <object class="wxFlexGridSizer" expanded="1">
                                            <property name="cols">2</property>
                                            <property name="flexible_direction">wxBOTH</property>
                                            <property name="growablecols"></property>
                                            <property name="growablerows"></property>
                                            <property name="hgap">0</property>
                                            <property name="minimum_size"></property>
                                            <property name="name">fgSizer1</property>
                                            <property name="non_flexible_grow_mode">wxFLEX_GROWMODE_SPECIFIED</property>
                                            <property name="permission">none</property>
                                            <property name="rows">1</property>
                                            <property name="vgap">0</property>
                                            <object class="sizeritem" expanded="1">
                                                <property name="border">5</property>
                                                <property name="flag">wxALL|wxALIGN_CENTER_VERTICAL</property>
                                                <property name="proportion">0</property>
                                                <object class="wxButton" expanded="1">
                                                    <property name="BottomDockable">1</property>
                                                    <property name="LeftDockable">1</property>
                                                    <property name="RightDockable">1</property>
                                                    <property name="TopDockable">1</property>
                                                    <property name="aui_layer"></property>
                                                    <property name="aui_name"></property>
                                                    <property name="aui_position"></property>
                                                    <property name="aui_row"></property>
                                                    <property name="best_size"></property>
                                                    <property name="bg"></property>
                                                    <property name="caption"></property>
                                                    <property name="caption_visible">1</property>
                                                    <property name="center_pane">0</property>
                                                    <property name="close_button">1</property>
                                                    <property name="context_help"></property>
                                                    <property name="context_menu">1</property>
                                                    <property name="default">0</property>
                                                    <property name="default_pane">0</property>
                                                    <property name="dock">Dock</property>
                                                    <property name="dock_fixed">0</property>
                                                    <property name="docking">Left</property>
                                                    <property name="enabled">1</property>
                                                    <property name="fg"></property>
                                                    <property name="floatable">1</property>
                                                    <property name="font"></property>
                                                    <property name="gripper">0</property>
                                                    <property name="hidden">0</property>
                                                    <property name="id">wxID_ANY</property>
                                                    <property name="label">OK</property>
                                                    <property name="max_size"></property>
                                                    <property name="maximize_button">0</property>
                                                    <property name="maximum_size"></property>
                                                    <property name="min_size"></property>
                                                    <property name="minimize_button">0</property>
                                                    <property name="minimum_size"></property>
                                                    <property name="moveable">1</property>
                                                    <property name="name">m_button1</property>
                                                    <property name="pane_border">1</property>
                                                    <property name="pane_position"></property>
                                                    <property name="pane_size"></property>
                                                    <property name="permission">protected</property>
                                                    <property name="pin_button">1</property>
                                                    <property name="pos"></property>
                                                    <property name="resize">Resizable</property>
                                                    <property name="show">1</property>
                                                    <property name="size"></property>
                                                    <property name="style"></property>
                                                    <property name="subclass"></property>
                                                    <property name="toolbar_pane">0</property>
                                                    <property name="tooltip"></property>
                                                    <property name="validator_data_type"></property>
                                                    <property name="validator_style">wxFILTER_NONE</property>
                                                    <property name="validator_type">wxDefaultValidator</property>
                                                    <property name="validator_variable"></property>
                                                    <property name="window_extra_style"></property>
                                                    <property name="window_name"></property>
                                                    <property name="window_style"></property>
                                                    <event name="OnButtonClick">OnButtunOK</event>
                                                    <event name="OnChar"></event>
                                                    <event name="OnEnterWindow"></event>
                                                    <event name="OnEraseBackground"></event>
                                                    <event name="OnKeyDown"></event>
                                                    <event name="OnKeyUp"></event>
                                                    <event name="OnKillFocus"></event>
                                                    <event name="OnLeaveWindow"></event>
                                                    <event name="OnLeftDClick"></event>
                                                    <event name="OnLeftDown"></event>
                                                    <event name="OnLeftUp"></event>
                                                    <event name="OnMiddleDClick"></event>
                                                    <event name="OnMiddleDown"></event>
                                                    <event name="OnMiddleUp"></event>
                                                    <event name="OnMotion"></event>
                                                    <event name="OnMouseEvents"></event>
                                                    <event name="OnMouseWheel"></event>
                                                    <event name="OnPaint"></event>
                                                    <event name="OnRightDClick"></event>
                                                    <event name="OnRightDown"></event>
                                                    <event name="OnRightUp"></event>
                                                    <event name="OnSetFocus"></event>
                                                    <event name="OnSize"></event>
                                                    <event name="OnUpdateUI"></event>
                                                </object>
                                            </object>
                                            <object class="sizeritem" expanded="1">
                                                <property name="border">5</property>
                                                <property name="flag">wxALL|wxALIGN_CENTER_VERTICAL</property>
                                                <property name="proportion">0</property>
                                                <object class="wxButton" expanded="1">
                                                    <property name="BottomDockable">1</property>
                                                    <property name="LeftDockable">1</property>
                                                    <property name="RightDockable">1</property>
                                                    <property name="TopDockable">1</property>
                                                    <property name="aui_layer"></property>
                                                    <property name="aui_name"></property>
                                                    <property name="aui_position"></property>
                                                    <property name="aui_row"></property>
                                                    <property name="best_size"></property>
                                                    <property name="bg"></property>
                                                    <property name="caption"></property>
                                                    <property name="caption_visible">1</property>
                                                    <property name="center_pane">0</property>
                                                    <property name="close_button">1</property>
                                                    <property name="context_help"></property>
                                                    <property name="context_menu">1</property>
                                                    <property name="default">0</property>
                                                    <property name="default_pane">0</property>
                                                    <property name="dock">Dock</property>
                                                    <property name="dock_fixed">0</property>
                                                    <property name="docking">Left</property>
                                                    <property name="enabled">1</property>
                                                    <property name="fg"></property>
                                                    <property name="floatable">1</property>
                                                    <property name="font"></property>
                                                    <property name="gripper">0</property>
                                                    <property name="hidden">0</property>
                                                    <property name="id">wxID_ANY</property>
                                                    <property name="label">CLEAR</property>
                                                    <property name="max_size"></property>
                                                    <property name="maximize_button">0</property>
                                                    <property name="maximum_size"></property>
                                                    <property name="min_size"></property>
                                                    <property name="minimize_button">0</property>
                                                    <property name="minimum_size"></property>
                                                    <property name="moveable">1</property>
                                                    <property name="name">m_button2</property>
                                                    <property name="pane_border">1</property>
                                                    <property name="pane_position"></property>
                                                    <property name="pane_size"></property>
                                                    <property name="permission">protected</property>
                                                    <property name="pin_button">1</property>
                                                    <property name="pos"></property>
                                                    <property name="resize">Resizable</property>
                                                    <property name="show">1</property>
                                                    <property name="size"></property>
                                                    <property name="style"></property>
                                                    <property name="subclass"></property>
                                                    <property name="toolbar_pane">0</property>
                                                    <property name="tooltip"></property>
                                                    <property name="validator_data_type"></property>
                                                    <property name="validator_style">wxFILTER_NONE</property>
                                                    <property name="validator_type">wxDefaultValidator</property>
                                                    <property name="validator_variable"></property>
                                                    <property name="window_extra_style"></property>
                                                    <property name="window_name"></property>
                                                    <property name="window_style"></property>
                                                    <event name="OnButtonClick">OnButtunCLEAR</event>
                                                    <event name="OnChar"></event>
                                                    <event name="OnEnterWindow"></event>
                                                    <event name="OnEraseBackground"></event>
                                                    <event name="OnKeyDown"></event>
                                                    <event name="OnKeyUp"></event>
                                                    <event name="OnKillFocus"></event>
                                                    <event name="OnLeaveWindow"></event>
                                                    <event name="OnLeftDClick"></event>
                                                    <event name="OnLeftDown"></event>
                                                    <event name="OnLeftUp"></event>
                                                    <event name="OnMiddleDClick"></event>
                                                    <event name="OnMiddleDown"></event>
                                                    <event name="OnMiddleUp"></event>
                                                    <event name="OnMotion"></event>
                                                    <event name="OnMouseEvents"></event>
                                                    <event name="OnMouseWheel"></event>
                                                    <event name="OnPaint"></event>
                                                    <event name="OnRightDClick"></event>
                                                    <event name="OnRightDown"></event>
                                                    <event name="OnRightUp"></event>
                                                    <event name="OnSetFocus"></event>
                                                    <event name="OnSize"></event>
                                                    <event name="OnUpdateUI"></event>
                                                </object>
                                            </object>
                                        </object>
                                    </object>
                                </object>
                            </object>
                        </object>
                    </object>
                </object>
            </object>
        </object>
    </object>
</wxFormBuilder_Project>
  • pytest.py : F8(File-> Generate Code) でwxFormbuilderが吐き出したファイル

Project の Properties の file で設定した名前になる。設定しないと noname.py

# -*- coding: utf-8 -*- 

###########################################################################
## Python code generated with wxFormBuilder (version May 15 2013)
## http://www.wxformbuilder.org/
##
## PLEASE DO "NOT" EDIT THIS FILE!
###########################################################################

import wx
import wx.xrc

###########################################################################
## Class fMain
###########################################################################

class fMain ( wx.Frame ):
    
    def __init__( self, parent ):
        wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = u"wxFormbuilder TEST", pos = wx.DefaultPosition, size = wx.Size( 500,300 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )
        
        self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )
        
        bSizer1 = wx.BoxSizer( wx.VERTICAL )
        
        self.m_panel1 = wx.Panel( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL )
        bSizer2 = wx.BoxSizer( wx.VERTICAL )
        
        self.m_textCtrl1 = wx.TextCtrl( self.m_panel1, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0 )
        bSizer2.Add( self.m_textCtrl1, 1, wx.ALL|wx.EXPAND, 5 )
        
        bSizer3 = wx.BoxSizer( wx.HORIZONTAL )
        
        fgSizer1 = wx.FlexGridSizer( 1, 2, 0, 0 )
        fgSizer1.SetFlexibleDirection( wx.BOTH )
        fgSizer1.SetNonFlexibleGrowMode( wx.FLEX_GROWMODE_SPECIFIED )
        
        self.m_button1 = wx.Button( self.m_panel1, wx.ID_ANY, u"OK", wx.DefaultPosition, wx.DefaultSize, 0 )
        fgSizer1.Add( self.m_button1, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 )
        
        self.m_button2 = wx.Button( self.m_panel1, wx.ID_ANY, u"CLEAR", wx.DefaultPosition, wx.DefaultSize, 0 )
        fgSizer1.Add( self.m_button2, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 )
        
        
        bSizer3.Add( fgSizer1, 0, 0, 5 )
        
        
        bSizer2.Add( bSizer3, 0, wx.ALIGN_CENTER_HORIZONTAL, 5 )
        
        
        self.m_panel1.SetSizer( bSizer2 )
        self.m_panel1.Layout()
        bSizer2.Fit( self.m_panel1 )
        bSizer1.Add( self.m_panel1, 1, wx.EXPAND, 5 )
        
        
        self.SetSizer( bSizer1 )
        self.Layout()
        
        self.Centre( wx.BOTH )
        
        # Connect Events
        # イベントが追加されています。
        self.m_button1.Bind( wx.EVT_BUTTON, self.OnButtunOK )
        self.m_button2.Bind( wx.EVT_BUTTON, self.OnButtunCLEAR )
    
    def __del__( self ):
        pass
    
    
    # Virtual event handlers, overide them in your derived class
    def OnButtunOK( self, event ):
        event.Skip()
    
    def OnButtunCLEAR( self, event ):
        event.Skip()

Tools の「Generate Inherited Class F6」をクリックすると継承ファイルを作ります。

f:id:sirocco:20140726125510j:image

  • pytestfMain.py : 継承してwxFormBuilderが作成したファイル。
"""Subclass of fMain, which is generated by wxFormBuilder."""

import wx
import pytest

# Implementing fMain
class pytestfMain( pytest.fMain ):
    def __init__( self, parent ):
        pytest.fMain.__init__( self, parent )

    # Handlers for fMain events.
    def OnButtunOK( self, event ):
        self.m_textCtrl1.AppendText('OK') # これを書き加えた

    def OnButtunCLEAR( self, event ):
        self.m_textCtrl1.Clear()          # これを書き加えた
  • pytestApp.py : 新たに作ったメイン
import wx
from pytestfMain import pytestfMain as fMain

app = wx.App()
frame = fMain(None)
# アイコンを表示するようにしました。
frame.SetIcon(wx.Icon("wxwin.ico",wx.BITMAP_TYPE_ICO))
frame.Show()
app.SetTopWindow(frame)
app.MainLoop()

wxFormbuilderが吐き出すソースはTABによるインデントなのでスペースでインデントするとエラーになります。テキストエディダの置換でスペースに変換しましょう。