简单使用python GUI工具 wxFormBuilder

由于工作中的一些需要想要用python写一个小工具,当写完一个基本的使用程序之后,自己运行之后觉得不错,发给别的同事用的时候他们说要是有个界面就好了,于是就有了下边的东西:
本来自己使用python wxpython一行一行的凑布局觉得也不错,组件稍微一多就不像凑了,于是有了下边这个软件:
wxFormbuilder  可以自动生成C++ python PHP Lua等代码,方便太多了。看两个例子:
![e1](https://img-blog.csdn.net/20160810212306927)
![e2](https://img-blog.csdn.net/20160810212341991)

是不是很方便:
再来看自动生成代码C++ python:

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

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

import wx
import wx.xrc

###########################################################################
## Class MyFrame1
###########################################################################

class MyFrame1 ( wx.Frame ):

    def __init__( self, parent ):
        wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = wx.EmptyString, pos = wx.DefaultPosition, size = wx.Size( 511,396 ), 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 )
        sbSizer1 = wx.StaticBoxSizer( wx.StaticBox( self.m_panel1, wx.ID_ANY, u"label" ), wx.HORIZONTAL )

        self.m_staticText2 = wx.StaticText( sbSizer1.GetStaticBox(), wx.ID_ANY, u"MyLabel", wx.DefaultPosition, wx.DefaultSize, 0 )
        self.m_staticText2.Wrap( -1 )
        sbSizer1.Add( self.m_staticText2, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 )

        self.m_textCtrl2 = wx.TextCtrl( sbSizer1.GetStaticBox(), wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0 )
        sbSizer1.Add( self.m_textCtrl2, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 )

        self.m_staticText3 = wx.StaticText( sbSizer1.GetStaticBox(), wx.ID_ANY, u"MyLabel", wx.DefaultPosition, wx.DefaultSize, 0 )
        self.m_staticText3.Wrap( -1 )
        sbSizer1.Add( self.m_staticText3, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 )

        self.m_textCtrl3 = wx.TextCtrl( sbSizer1.GetStaticBox(), wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0 )
        sbSizer1.Add( self.m_textCtrl3, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 )

        self.m_button1 = wx.Button( sbSizer1.GetStaticBox(), wx.ID_ANY, u"MyButton", wx.DefaultPosition, wx.DefaultSize, 0 )
        sbSizer1.Add( self.m_button1, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 )

        self.m_button2 = wx.Button( sbSizer1.GetStaticBox(), wx.ID_ANY, u"MyButton", wx.DefaultPosition, wx.DefaultSize, 0 )
        sbSizer1.Add( self.m_button2, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 )


        self.m_panel1.SetSizer( sbSizer1 )
        self.m_panel1.Layout()
        sbSizer1.Fit( self.m_panel1 )
        bSizer1.Add( self.m_panel1, 1, wx.EXPAND |wx.ALL, 5 )

        self.m_panel2 = wx.Panel( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL )
        bSizer4 = wx.BoxSizer( wx.VERTICAL )

        self.m_textCtrl6 = wx.TextCtrl( self.m_panel2, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.Size( 490,150 ), wx.HSCROLL|wx.TE_MULTILINE|wx.TE_RICH2 )
        bSizer4.Add( self.m_textCtrl6, 0, wx.ALL, 5 )

        self.m_panel7 = wx.Panel( self.m_panel2, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL )
        sbSizer2 = wx.StaticBoxSizer( wx.StaticBox( self.m_panel7, wx.ID_ANY, u"label" ), wx.HORIZONTAL )

        self.m_checkBox2 = wx.CheckBox( sbSizer2.GetStaticBox(), wx.ID_ANY, u"Check Me!", wx.DefaultPosition, wx.DefaultSize, 0 )
        sbSizer2.Add( self.m_checkBox2, 0, wx.ALL, 5 )

        self.m_checkBox3 = wx.CheckBox( sbSizer2.GetStaticBox(), wx.ID_ANY, u"Check Me!", wx.DefaultPosition, wx.DefaultSize, 0 )
        sbSizer2.Add( self.m_checkBox3, 0, wx.ALL, 5 )

        m_choice1Choices = []
        self.m_choice1 = wx.Choice( sbSizer2.GetStaticBox(), wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, m_choice1Choices, 0 )
        self.m_choice1.SetSelection( 0 )
        sbSizer2.Add( self.m_choice1, 0, wx.ALL, 5 )

        self.m_button6 = wx.Button( sbSizer2.GetStaticBox(), wx.ID_ANY, u"MyButton", wx.DefaultPosition, wx.DefaultSize, 0 )
        sbSizer2.Add( self.m_button6, 0, wx.ALL, 5 )

        self.m_button7 = wx.Button( sbSizer2.GetStaticBox(), wx.ID_ANY, u"MyButton", wx.DefaultPosition, wx.DefaultSize, 0 )
        sbSizer2.Add( self.m_button7, 0, wx.ALL, 5 )


        self.m_panel7.SetSizer( sbSizer2 )
        self.m_panel7.Layout()
        sbSizer2.Fit( self.m_panel7 )
        bSizer4.Add( self.m_panel7, 1, wx.EXPAND |wx.ALL, 5 )


        self.m_panel2.SetSizer( bSizer4 )
        self.m_panel2.Layout()
        bSizer4.Fit( self.m_panel2 )
        bSizer1.Add( self.m_panel2, 1, wx.EXPAND |wx.ALL, 5 )

        self.m_staticline1 = wx.StaticLine( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL )
        bSizer1.Add( self.m_staticline1, 0, wx.EXPAND |wx.ALL, 5 )

        self.m_panel3 = wx.Panel( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL )
        bSizer2 = wx.BoxSizer( wx.HORIZONTAL )

        self.m_textCtrl7 = wx.TextCtrl( self.m_panel3, wx.ID_ANY, wx.EmptyString, wx.Point( 10,10 ), wx.Size( 350,30 ), 0 )
        bSizer2.Add( self.m_textCtrl7, 0, wx.ALL, 5 )

        self.m_button3 = wx.Button( self.m_panel3, wx.ID_ANY, u"MyButton", wx.DefaultPosition, wx.DefaultSize, 0 )
        bSizer2.Add( self.m_button3, 0, wx.ALL, 5 )


        self.m_panel3.SetSizer( bSizer2 )
        self.m_panel3.Layout()
        bSizer2.Fit( self.m_panel3 )
        bSizer1.Add( self.m_panel3, 1, wx.EXPAND |wx.ALL, 5 )


        self.SetSizer( bSizer1 )
        self.Layout()
        self.m_statusBar1 = self.CreateStatusBar( 3, wx.ST_SIZEGRIP, wx.ID_ANY )
        self.m_statusBar1.SetForegroundColour( wx.SystemSettings.GetColour( wx.SYS_COLOUR_INACTIVECAPTIONTEXT ) )
        self.m_statusBar1.SetBackgroundColour( wx.SystemSettings.GetColour( wx.SYS_COLOUR_BTNSHADOW ) )


        self.Centre( wx.BOTH )

    def __del__( self ):
        pass


///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Feb 16 2016)
// http://www.wxformbuilder.org/
//
// PLEASE DO "NOT" EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////

#include "noname.h"

///////////////////////////////////////////////////////////////////////////

MyFrame1::MyFrame1( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxFrame( parent, id, title, pos, size, style )
{
    this->SetSizeHints( wxDefaultSize, wxDefaultSize );

    wxBoxSizer* bSizer1;
    bSizer1 = new wxBoxSizer( wxVERTICAL );

    m_panel1 = new wxPanel( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
    wxStaticBoxSizer* sbSizer1;
    sbSizer1 = new wxStaticBoxSizer( new wxStaticBox( m_panel1, wxID_ANY, wxT("label") ), wxHORIZONTAL );

    m_staticText2 = new wxStaticText( sbSizer1->GetStaticBox(), wxID_ANY, wxT("MyLabel"), wxDefaultPosition, wxDefaultSize, 0 );
    m_staticText2->Wrap( -1 );
    sbSizer1->Add( m_staticText2, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );

    m_textCtrl2 = new wxTextCtrl( sbSizer1->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
    #ifdef __WXGTK__
    if ( !m_textCtrl2->HasFlag( wxTE_MULTILINE ) )
    {
    m_textCtrl2->SetMaxLength(  );
    }
    #else
    m_textCtrl2->SetMaxLength(  );
    #endif
    sbSizer1->Add( m_textCtrl2, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );

    m_staticText3 = new wxStaticText( sbSizer1->GetStaticBox(), wxID_ANY, wxT("MyLabel"), wxDefaultPosition, wxDefaultSize, 0 );
    m_staticText3->Wrap( -1 );
    sbSizer1->Add( m_staticText3, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );

    m_textCtrl3 = new wxTextCtrl( sbSizer1->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
    #ifdef __WXGTK__
    if ( !m_textCtrl3->HasFlag( wxTE_MULTILINE ) )
    {
    m_textCtrl3->SetMaxLength(  );
    }
    #else
    m_textCtrl3->SetMaxLength(  );
    #endif
    sbSizer1->Add( m_textCtrl3, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );

    m_button1 = new wxButton( sbSizer1->GetStaticBox(), wxID_ANY, wxT("MyButton"), wxDefaultPosition, wxDefaultSize, 0 );
    sbSizer1->Add( m_button1, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );

    m_button2 = new wxButton( sbSizer1->GetStaticBox(), wxID_ANY, wxT("MyButton"), wxDefaultPosition, wxDefaultSize, 0 );
    sbSizer1->Add( m_button2, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );


    m_panel1->SetSizer( sbSizer1 );
    m_panel1->Layout();
    sbSizer1->Fit( m_panel1 );
    bSizer1->Add( m_panel1, 1, wxEXPAND | wxALL, 5 );

    m_panel2 = new wxPanel( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
    wxBoxSizer* bSizer4;
    bSizer4 = new wxBoxSizer( wxVERTICAL );

    m_textCtrl6 = new wxTextCtrl( m_panel2, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize( 490,150 ), wxHSCROLL|wxTE_MULTILINE|wxTE_RICH2 );
    #ifdef __WXGTK__
    if ( !m_textCtrl6->HasFlag( wxTE_MULTILINE ) )
    {
    m_textCtrl6->SetMaxLength(  );
    }
    #else
    m_textCtrl6->SetMaxLength(  );
    #endif
    bSizer4->Add( m_textCtrl6, 0, wxALL, 5 );

    m_panel7 = new wxPanel( m_panel2, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
    wxStaticBoxSizer* sbSizer2;
    sbSizer2 = new wxStaticBoxSizer( new wxStaticBox( m_panel7, wxID_ANY, wxT("label") ), wxHORIZONTAL );

    m_checkBox2 = new wxCheckBox( sbSizer2->GetStaticBox(), wxID_ANY, wxT("Check Me!"), wxDefaultPosition, wxDefaultSize, 0 );
    sbSizer2->Add( m_checkBox2, 0, wxALL, 5 );

    m_checkBox3 = new wxCheckBox( sbSizer2->GetStaticBox(), wxID_ANY, wxT("Check Me!"), wxDefaultPosition, wxDefaultSize, 0 );
    sbSizer2->Add( m_checkBox3, 0, wxALL, 5 );

    wxArrayString m_choice1Choices;
    m_choice1 = new wxChoice( sbSizer2->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, m_choice1Choices, 0 );
    m_choice1->SetSelection( 0 );
    sbSizer2->Add( m_choice1, 0, wxALL, 5 );

    m_button6 = new wxButton( sbSizer2->GetStaticBox(), wxID_ANY, wxT("MyButton"), wxDefaultPosition, wxDefaultSize, 0 );
    sbSizer2->Add( m_button6, 0, wxALL, 5 );

    m_button7 = new wxButton( sbSizer2->GetStaticBox(), wxID_ANY, wxT("MyButton"), wxDefaultPosition, wxDefaultSize, 0 );
    sbSizer2->Add( m_button7, 0, wxALL, 5 );


    m_panel7->SetSizer( sbSizer2 );
    m_panel7->Layout();
    sbSizer2->Fit( m_panel7 );
    bSizer4->Add( m_panel7, 1, wxEXPAND | wxALL, 5 );


    m_panel2->SetSizer( bSizer4 );
    m_panel2->Layout();
    bSizer4->Fit( m_panel2 );
    bSizer1->Add( m_panel2, 1, wxEXPAND | wxALL, 5 );

    m_staticline1 = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
    bSizer1->Add( m_staticline1, 0, wxEXPAND | wxALL, 5 );

    m_panel3 = new wxPanel( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
    wxBoxSizer* bSizer2;
    bSizer2 = new wxBoxSizer( wxHORIZONTAL );

    m_textCtrl7 = new wxTextCtrl( m_panel3, wxID_ANY, wxEmptyString, wxPoint( 10,10 ), wxSize( 350,30 ), 0 );
    #ifdef __WXGTK__
    if ( !m_textCtrl7->HasFlag( wxTE_MULTILINE ) )
    {
    m_textCtrl7->SetMaxLength(  );
    }
    #else
    m_textCtrl7->SetMaxLength(  );
    #endif
    bSizer2->Add( m_textCtrl7, 0, wxALL, 5 );

    m_button3 = new wxButton( m_panel3, wxID_ANY, wxT("MyButton"), wxDefaultPosition, wxDefaultSize, 0 );
    bSizer2->Add( m_button3, 0, wxALL, 5 );


    m_panel3->SetSizer( bSizer2 );
    m_panel3->Layout();
    bSizer2->Fit( m_panel3 );
    bSizer1->Add( m_panel3, 1, wxEXPAND | wxALL, 5 );


    this->SetSizer( bSizer1 );
    this->Layout();
    m_statusBar1 = this->CreateStatusBar( 3, wxST_SIZEGRIP, wxID_ANY );
    m_statusBar1->SetForegroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_INACTIVECAPTIONTEXT ) );
    m_statusBar1->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNSHADOW ) );


    this->Centre( wxBOTH );
}

MyFrame1::~MyFrame1()
{
}

你可能感兴趣的:(pythonTwisted)