#Boa:Frame:Frame1
import wx
import wx.lib.buttons
def create(parent):
return Frame1(parent)
[wxID_FRAME1, wxID_FRAME1ADD, wxID_FRAME1BACKSPACE, wxID_FRAME1CLEAR,
wxID_FRAME1DEVIDE, wxID_FRAME1DOT, wxID_FRAME1EIGHT, wxID_FRAME1EQUAL,
wxID_FRAME1FIVE, wxID_FRAME1FOUR, wxID_FRAME1LEFT, wxID_FRAME1MINUS,
wxID_FRAME1MULTIPLY, wxID_FRAME1NINE, wxID_FRAME1ONE, wxID_FRAME1PANEL1,
wxID_FRAME1RIGHT, wxID_FRAME1SEVEN, wxID_FRAME1SIX, wxID_FRAME1TEXT,
wxID_FRAME1THREE, wxID_FRAME1TWO, wxID_FRAME1ZERO,
] = [wx.NewId() for _init_ctrls in range(23)]
class Frame1(wx.Frame):
def _init_ctrls(self, prnt):
# generated method, don‘t edit
wx.Frame.__init__(self, id=wxID_FRAME1, name=‘‘, parent=prnt,
pos=wx.Point(502, 176), size=wx.Size(273, 280),
style=wx.DEFAULT_FRAME_STYLE, title=u‘\u8ba1\u7b97\u5668‘)
self.SetClientSize(wx.Size(257, 242))
self.SetMaxSize(wx.Size(273, 280))
self.panel1 = wx.Panel(id=wxID_FRAME1PANEL1, name=‘panel1‘, parent=self,
pos=wx.Point(0, 0), size=wx.Size(257, 242),
style=wx.TAB_TRAVERSAL)
self.text = wx.TextCtrl(id=wxID_FRAME1TEXT, name=u‘text‘,
parent=self.panel1, pos=wx.Point(8, 8), size=wx.Size(240, 24),
style=0, value=u‘0‘)
self.text.SetEditable(False)
self.text.Enable(True)
self.text.SetAutoLayout(False)
self.text.SetInsertionPoint(0)
self.text.SetThemeEnabled(False)
self.one = wx.lib.buttons.GenButton(id=wxID_FRAME1ONE, label=u‘1‘,
name=u‘one‘, parent=self.panel1, pos=wx.Point(8, 48),
size=wx.Size(48, 25), style=0)
self.one.Bind(wx.EVT_BUTTON, self.OnOneButton, id=wxID_FRAME1ONE)
self.two = wx.lib.buttons.GenButton(id=wxID_FRAME1TWO, label=u‘2‘,
name=u‘two‘, parent=self.panel1, pos=wx.Point(72, 48),
size=wx.Size(48, 25), style=0)
self.two.Bind(wx.EVT_BUTTON, self.OnTwoButton, id=wxID_FRAME1TWO)
self.three = wx.lib.buttons.GenButton(id=wxID_FRAME1THREE, label=u‘3‘,
name=u‘three‘, parent=self.panel1, pos=wx.Point(136, 48),
size=wx.Size(48, 25), style=0)
self.three.Bind(wx.EVT_BUTTON, self.OnThreeButton, id=wxID_FRAME1THREE)
self.four = wx.lib.buttons.GenButton(id=wxID_FRAME1FOUR, label=u‘4‘,
name=u‘four‘, parent=self.panel1, pos=wx.Point(8, 88),
size=wx.Size(48, 25), style=0)
self.four.Bind(wx.EVT_BUTTON, self.OnFourButton, id=wxID_FRAME1FOUR)
self.five = wx.lib.buttons.GenButton(id=wxID_FRAME1FIVE, label=u‘5‘,
name=u‘five‘, parent=self.panel1, pos=wx.Point(72, 88),
size=wx.Size(48, 25), style=0)
self.five.Bind(wx.EVT_BUTTON, self.OnFiveButton, id=wxID_FRAME1FIVE)
self.six = wx.lib.buttons.GenButton(id=wxID_FRAME1SIX, label=u‘6‘,
name=u‘six‘, parent=self.panel1, pos=wx.Point(136, 88),
size=wx.Size(48, 25), style=0)
self.six.Bind(wx.EVT_BUTTON, self.OnSixButton, id=wxID_FRAME1SIX)
self.seven = wx.lib.buttons.GenButton(id=wxID_FRAME1SEVEN, label=u‘7‘,
name=u‘seven‘, parent=self.panel1, pos=wx.Point(8, 128),
size=wx.Size(48, 25), style=0)
self.seven.Bind(wx.EVT_BUTTON, self.OnSevenButton, id=wxID_FRAME1SEVEN)
self.eight = wx.lib.buttons.GenButton(id=wxID_FRAME1EIGHT, label=u‘8‘,
name=u‘eight‘, parent=self.panel1, pos=wx.Point(72, 128),
size=wx.Size(48, 25), style=0)
self.eight.Bind(wx.EVT_BUTTON, self.OnEightButton, id=wxID_FRAME1EIGHT)
self.nine = wx.lib.buttons.GenButton(id=wxID_FRAME1NINE, label=u‘9‘,
name=u‘nine‘, parent=self.panel1, pos=wx.Point(136, 128),
size=wx.Size(48, 25), style=0)
self.nine.Bind(wx.EVT_BUTTON, self.OnNineButton, id=wxID_FRAME1NINE)
self.add = wx.lib.buttons.GenButton(id=wxID_FRAME1ADD, label=u‘+‘,
name=u‘add‘, parent=self.panel1, pos=wx.Point(200, 48),
size=wx.Size(48, 25), style=0)
self.add.Bind(wx.EVT_BUTTON, self.OnAddButton, id=wxID_FRAME1ADD)
self.minus = wx.lib.buttons.GenButton(id=wxID_FRAME1MINUS, label=u‘-‘,
name=u‘minus‘, parent=self.panel1, pos=wx.Point(200, 88),
size=wx.Size(48, 25), style=0)
self.minus.Bind(wx.EVT_BUTTON, self.OnMinusButton, id=wxID_FRAME1MINUS)
self.multiply = wx.lib.buttons.GenButton(id=wxID_FRAME1MULTIPLY,
label=u‘*‘, name=u‘multiply‘, parent=self.panel1,
pos=wx.Point(200, 128), size=wx.Size(48, 25), style=0)
self.multiply.Bind(wx.EVT_BUTTON, self.OnMultiplyButton,
id=wxID_FRAME1MULTIPLY)
self.devide = wx.lib.buttons.GenButton(id=wxID_FRAME1DEVIDE, label=u‘/‘,
name=u‘devide‘, parent=self.panel1, pos=wx.Point(200, 168),
size=wx.Size(48, 25), style=0)
self.devide.Bind(wx.EVT_BUTTON, self.OnDevideButton,
id=wxID_FRAME1DEVIDE)
self.equal = wx.lib.buttons.GenButton(id=wxID_FRAME1EQUAL, label=u‘=‘,
name=u‘equal‘, parent=self.panel1, pos=wx.Point(200, 208),
size=wx.Size(48, 25), style=0)
self.equal.Bind(wx.EVT_BUTTON, self.OnEqualButton, id=wxID_FRAME1EQUAL)
self.backspace = wx.lib.buttons.GenButton(id=wxID_FRAME1BACKSPACE,
label=u‘<-‘, name=u‘backspace‘, parent=self.panel1,
pos=wx.Point(8, 168), size=wx.Size(48, 25), style=0)
self.backspace.Bind(wx.EVT_BUTTON, self.OnBackspaceButton,
id=wxID_FRAME1BACKSPACE)
self.zero = wx.lib.buttons.GenButton(id=wxID_FRAME1ZERO, label=u‘0‘,
name=u‘zero‘, parent=self.panel1, pos=wx.Point(72, 168),
size=wx.Size(48, 25), style=0)
self.zero.Bind(wx.EVT_BUTTON, self.OnZeroButton, id=wxID_FRAME1ZERO)
self.dot = wx.lib.buttons.GenButton(id=wxID_FRAME1DOT, label=u‘.‘,
name=u‘dot‘, parent=self.panel1, pos=wx.Point(136, 168),
size=wx.Size(48, 25), style=0)
self.dot.Bind(wx.EVT_BUTTON, self.OnDotButton, id=wxID_FRAME1DOT)
self.clear = wx.lib.buttons.GenButton(id=wxID_FRAME1CLEAR,
label=u‘clear‘, name=u‘clear‘, parent=self.panel1, pos=wx.Point(8,
208), size=wx.Size(48, 25), style=0)
self.clear.Bind(wx.EVT_BUTTON, self.OnClearButton, id=wxID_FRAME1CLEAR)
self.left = wx.lib.buttons.GenButton(id=wxID_FRAME1LEFT, label=u‘(‘,
name=u‘left‘, parent=self.panel1, pos=wx.Point(72, 208),
size=wx.Size(48, 25), style=0)
self.left.Bind(wx.EVT_BUTTON, self.OnLeftButton, id=wxID_FRAME1LEFT)
self.right = wx.lib.buttons.GenButton(id=wxID_FRAME1RIGHT, label=u‘)‘,
name=u‘right‘, parent=self.panel1, pos=wx.Point(136, 208),
size=wx.Size(48, 25), style=0)
self.right.Bind(wx.EVT_BUTTON, self.OnRightButton, id=wxID_FRAME1RIGHT)
def __init__(self, parent):
self._init_ctrls(parent)
def OnOneButton(self, event):
stri = self.text.GetValue()
if stri=="0":
self.text.SetValue("1")
else:
self.text.SetValue(stri+"1")
event.Skip()
def OnTwoButton(self, event):
stri = self.text.GetValue()
if stri=="0":
self.text.SetValue("2")
else:
self.text.SetValue(stri+"2")
event.Skip()
def OnThreeButton(self, event):
stri = self.text.GetValue()
if stri=="0":
self.text.SetValue("3")
else:
self.text.SetValue(stri+"3")
event.Skip()
def OnFourButton(self, event):
stri = self.text.GetValue()
if stri=="0":
self.text.SetValue("4")
else:
self.text.SetValue(stri+"4")
event.Skip()
def OnFiveButton(self, event):
stri = self.text.GetValue()
if stri=="0":
self.text.SetValue("5")
else:
self.text.SetValue(stri+"5")
event.Skip()
def OnSixButton(self, event):
stri = self.text.GetValue()
if stri=="0":
self.text.SetValue("6")
else:
self.text.SetValue(stri+"6")
event.Skip()
def OnSevenButton(self, event):
stri = self.text.GetValue()
if stri=="0":
self.text.SetValue("7")
else:
self.text.SetValue(stri+"7")
event.Skip()
def OnEightButton(self, event):
stri = self.text.GetValue()
if stri=="0":
self.text.SetValue("8")
else:
self.text.SetValue(stri+"8")
event.Skip()
def OnNineButton(self, event):
stri = self.text.GetValue()
if stri=="0":
self.text.SetValue("9")
else:
self.text.SetValue(stri+"9")
event.Skip()
def OnZeroButton(self, event):
stri = self.text.GetValue()
if stri=="0":
self.text.SetValue("0")
else:
self.text.SetValue(stri+"0")
event.Skip()
def OnAddButton(self, event):
self.text.SetValue(self.text.GetValue()+"+")
event.Skip()
def OnMinusButton(self, event):
self.text.SetValue(self.text.GetValue()+"-")
event.Skip()
def OnMultiplyButton(self, event):
self.text.SetValue(self.text.GetValue()+"*")
event.Skip()
def OnDevideButton(self, event):
self.text.SetValue(self.text.GetValue()+"/")
event.Skip()
def OnBackspaceButton(self, event):
stri = self.text.GetValue()
if len(stri)==1:
self.text.SetValue("0")
else:
self.text.SetValue(stri[0:(len(stri)-1)])
event.Skip()
def OnDotButton(self, event):
self.text.SetValue(self.text.GetValue()+".")
event.Skip()
def OnClearButton(self, event):
self.text.SetValue("0")
event.Skip()
def OnLeftButton(self, event):
stri = self.text.GetValue()
if stri=="0":
self.text.SetValue("(")
else:
self.text.SetValue(stri+"(")
event.Skip()
def OnRightButton(self, event):
stri = self.text.GetValue()
if stri=="0":
self.text.SetValue(")")
else:
self.text.SetValue(stri+")")
event.Skip()
def OnEqualButton(self, event):
try:
a = eval(self.text.GetValue())
a = str(a)
except:
a = u‘\u8868\u8fbe\u5f0f\u8f93\u5165\u9519\u8bef‘
self.text.SetValue(a)
event.Skip()
if __name__ == ‘__main__‘:
app = wx.PySimpleApp()
frame = create(None)
frame.Show()
app.MainLoop()
使用boa开发工具开发wxpython——计算器,布布扣,bubuko.com
使用boa开发工具开发wxpython——计算器