wxpython 基础代码
import wx
class MyFrame ( wx. Frame) :
def __init__ ( self) :
super ( ) . __init__( parent= None , title= '计算器' , size= ( 450 , 250 ) )
panel = wx. Panel( self)
self. icon1 = wx. Icon( name= "test.ico" , type = wx. BITMAP_TYPE_PNG)
self. SetIcon( self. icon1)
self. text_ctrl = wx. TextCtrl( panel, pos= ( 30 , 20 ) , size= ( 80 , 25 ) )
self. text_ctrl. SetValue( "加数1" )
self. jia= wx. StaticText( panel, label= "+" , pos= ( 120 , 20 ) )
self. text_ctrl01 = wx. TextCtrl( panel, pos= ( 160 , 20 ) , size= ( 80 , 25 ) )
self. text_ctrl01. SetValue( "加数2" )
self. dengyu= wx. StaticText( panel, label= "=" , pos= ( 260 , 20 ) )
self. text_ctrl02 = wx. TextCtrl( panel, pos= ( 290 , 20 ) )
self. text_ctrl02. SetValue( "他们的和" )
self. button = wx. Button( panel, label= 'Click Me' , pos= ( 120 , 60 ) )
self. button. Bind( wx. EVT_BUTTON, self. on_button_click)
self. button01 = wx. Button( panel, label= '求和' , pos= ( 120 , 100 ) )
self. button01. Bind( wx. EVT_BUTTON, self. on_button_click01)
def on_button_click ( self, event) :
message = self. text_ctrl. GetValue( )
wx. MessageBox( message, 'Message' , wx. OK | wx. ICON_INFORMATION)
def on_button_click01 ( self, event) :
a= float ( self. text_ctrl. GetValue( ) )
b= float ( self. text_ctrl01. GetValue( ) )
if isinstance ( a, ( int , float ) ) and isinstance ( b, ( int , float ) ) :
print ( "整数" )
message = a+ b
self. text_ctrl02. SetValue( str ( message) )
class MyApp ( wx. App) :
def OnInit ( self) :
frame = MyFrame( )
frame. Show( )
return True
if __name__ == "__main__" :
app = MyApp( )
app. MainLoop( )