' Created on 2015-6-16 @author: Jianan ' ' #!/usr/bin/python #-*-coding:utf-8 '-*-# calculator.py Import WX Class Example (WX. Frame): bianliang1 = ' 0 ' bianliang2 = ' 0 ' judge = ' def __init__ (self, Parent, title): Super (Example, self). __init__ (parent, Title=title, size=) self. Initui () self. Centre () self.
Show () def OnButtonClick0 (Self, event): var = self.display.GetValue () var = int (var) *10 + 0
Self.display.Value = Str (VAR) def OnButtonClick1 (Self, event): var = self.display.GetValue () var = int (var) *10 + 1 self.display.Value = str (VAR) def OnButtonClick2 (Self, event): var = Self.display.GetValue () var = int (var) *10 + 2 self.display.Value = str (VAR) def Onbuttonclic
K3 (self, event): var = self.display.GetValue () var = int (var) *10 + 3 Self.display.Value = str (VAR) def OnButtonClick4 (self, event): var = self.display.GetValue () var = int (var) *10 + 4 Self.display . Value = Str (VAR) def OnButtonClick5 (Self, event): var = self.display.GetValue () var = int (var ) *10 + 5 Self.display.Value = str (VAR) def OnButtonClick6 (Self, event): var = self.display.GetVal
UE () var = int (var) *10 + 6 self.display.Value = str (VAR) def OnButtonClick7 (Self, event): var = self.display.GetValue () var = int (var) *10 + 7 Self.display.Value = str (VAR) def on ButtonClick8 (self, event): var = self.display.GetValue () var = int (var) *10 + 8 Self.display.Value
= Str (VAR) def OnButtonClick9 (Self, event): var = self.display.GetValue () var = int (var) *10 + 9
Self.display.Value = Str (VAR) def onbuttoncls (Self, event): Self.display.Value = ' 0 ' def onbuttonbck (self, EVent): var = self.display.GetValue () var = int (var)/10 self.display.Value = str (VAR) def onbuttonclickclose (self, event): WX. Exit () def Onbuttonclickjia (Self, event): Self.bianliang1 = Self.display.GetValue () self.disp Lay. Value = ' 0 ' self.judge= ' + ' def Onbuttonclickjian (Self, event): Self.bianliang1 = Self.display .
GetValue () Self.display.Value = ' 0 ' self.judge= '-"Def Onbuttonclickche" (Self, Event): Self.bianliang1 = Self.display.GetValue () Self.display.Value = ' 0 ' self.judge= "*" Def Onbutt Onclickchu (self, event): Self.bianliang1 = Self.display.GetValue () Self.display.Value = ' 0 ' self.j Udge= "/" Def onbuttonclickequ (Self, event): Bianliang2 = Self.display.GetValue () if SELF.JUDG
E = = ' + ': self.display.Value = str (int (self.bianliang1) +int (bianliang2))elif Self.judge = = '-': Self.display.Value = str (int (self.bianliang1)-int (bianliang2)) Elif Self.judge
= = ' * ': Self.display.Value = str (int (self.bianliang1) *int (bianliang2)) elif Self.judge = = '/': Self.display.Value = str (int (self.bianliang1)/int (bianliang2)) def initui (self): menubar = Wx. MenuBar () Filemenu = WX. Menu () menubar. Append (Filemenu, ' &file ') self. Setmenubar (menubar) VBox = wx. Boxsizer (WX. VERTICAL) Self.display = wx. Textctrl (self, style=wx.te_right,value= ' 0 ') vbox. ADD (Self.display, flag=wx. Expand|wx. Top|wx. BOTTOM, border=4) GS = WX. Gridsizer (5, 5, 5, 5) Buttoncls = WX. Button (self, label= ' Cls ') buttonbck = wx. Button (self, label= ' Bck ') Buttonclose = wx. Button (self, label= ' close ') button7 = wx. Button (self, label= ' 7 ') Button8 = wx. Button (self, label= ' 8 ') Button9 = wx. Button (selF, label= ' 9 ') Buttonchu = wx. Button (self, label= '/') Button4 = wx. Button (Self, label= ' 4 ') button5 = wx. Button (Self, label= ' 5 ') Button6 = wx. Button (Self, label= ' 6 ') Buttonchen = wx. Button (Self, label= ' * ') button1 = wx. Button (self, label= ' 1 ') Button2 = wx. Button (Self, label= ' 2 ') Button3 = wx. Button (Self, label= ' 3 ') Buttonjian = wx. Button (self, label= '-') Button0 = wx. Button (self, label= ' 0 ') Buttondot = wx.
Button (self, label= '. ') buttonequ = wx. Button (self, label= ' = ') Buttonplus = wx. Button (self, label= ' + ') Gs. Addmany ([buttoncls, 0, WX. EXPAND), (buttonbck, 0, WX. EXPAND), (WX. Statictext (self), WX. EXPAND), (buttonclose, 0, WX. EXPAND), (button7, 0, WX. EXPAND), (button8, 0, WX. EXPAND), (button9, 0, WX. EXPAND), (Buttonchu, 0, WX. EXPAND), (button4, 0, WX.
EXPAND), (button5, 0, WX.) EXPAND), (button6, 0, WX. EXPAND), (buttonchen, 0, WX. EXPAND), (button1, 0, WX. EXPAND), (button2, 0, WX. EXPAND), (button3, 0, WX. EXPAND), (Buttonjian, 0, WX. EXPAND), (button0, 0, WX. EXPAND), (Buttondot, 0, WX. EXPAND), (buttonequ, 0, WX. EXPAND), (buttonplus, 0, WX. EXPAND)] Buttoncls.bind (WX. Evt_button,self. ONBUTTONCLS) Buttonbck.bind (WX. Evt_button,self. ONBUTTONBCK) Buttonclose.bind (WX. Evt_button,self. Onbuttonclickclose) Button0. Bind (WX. Evt_button,self. ONBUTTONCLICK0) button1. Bind (WX. Evt_button,self. ONBUTTONCLICK1) button2. Bind (WX. Evt_button,self. OnButtonClick2) Button3. Bind (WX. Evt_button,self. ONBUTTONCLICK3) Button4. Bind (WX. Evt_button,self. ONBUTTONCLICK4) button5. Bind (WX. Evt_button,self. ONBUTTONCLICK5) Button6. Bind (WX. Evt_button,self. OnbuttonCLICK6) button7. Bind (WX. Evt_button,self. ONBUTTONCLICK7) Button8. Bind (WX. Evt_button,self. ONBUTTONCLICK8) Button9. Bind (WX. Evt_button,self. ONBUTTONCLICK9) Buttonequ.bind (WX. Evt_button,self. onbuttonclickequ) Buttonplus.bind (WX. Evt_button,self. Onbuttonclickjia) Buttonjian.bind (WX. Evt_button,self. Onbuttonclickjian) Buttonchen.bind (WX. Evt_button,self. Onbuttonclickche) Buttonchu.bind (WX. Evt_button,self. Onbuttonclickchu) VBox. ADD (GS, Proportion=1, flag=wx.) EXPAND) self. Setsizer (vbox) app = wx. App () Example (None, title= ' Calculator ') app. Mainloop ()