Python implements a calculator using wxPython and pythonwxpython

Source: Internet
Author: User

Python implements a calculator using wxPython and pythonwxpython

The examples in this article share with you the specific code for implementing the wxPython calculator for your reference. The specific content is as follows:

#-*-Coding: UTF-8 -*-#################################### ######## Python code generated with wxFormBuilder (version Feb 16 2016) # http://www.wxformbuilder.org/#### please do "NOT" edit this file! ######################################## # Import wximport wx. xrcimport math ###################################### ######### 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 (486,448), style = wx. DEFAULT_FRAME_STYLE | wx. TAB_TRAVERSAL) self. setSizeHintsSz (wx. defaultSize, wx. defaultSize) bSizer1 = wx. boxSizer (wx. VERTICAL) self. m_textCtrl1 = wx. textCtrl (self, wx. ID_ANY, wx. emptyString, wx. defaultPosition, wx. size (600, 60), style = wx. TE_RIGHT) self. m_textCtrl1.SetMinSize (wx. size (470, 60) bSizer1.Add (self. m_textCtrl1, 0, wx. ALL, 5) bSizer2 = wx. boxSizer (wx. HORIZONTAL) self. m_button1 = wx. button (self, wx. ID_ANY, u "return", wx. defaultPosition, wx. size (110, 60), 0) bSizer2.Add (self. m_button1, 0, wx. ALL, 5) self. m_button2 = wx. button (self, wx. ID_ANY, u "clear screen", wx. defaultPosition, wx. size (110, 60), 0) bSizer2.Add (self. m_button2, 0, wx. ALL, 5) self. m_button3 = wx. button (self, wx. ID_ANY, u "sqrt", wx. defaultPosition, wx. size (110, 60), 0) bSizer2.Add (self. m_button3, 0, wx. ALL, 5) self. m_button4 = wx. button (self, wx. ID_ANY, u "/", wx. defaultPosition, wx. size (110, 60), 0) bSizer2.Add (self. m_button4, 0, wx. ALL, 5) bSizer1.Add (bSizer2, 0, wx. EXPAND, 5) bSizer6 = wx. boxSizer (wx. HORIZONTAL) self. m_button10 = wx. button (self, wx. ID_ANY, u "7", wx. defaultPosition, wx. size (110, 60), 0) bSizer6.Add (self. m_button10, 0, wx. ALL, 5) self. m_button11 = wx. button (self, wx. ID_ANY, u "8", wx. defaultPosition, wx. size (110, 60), 0) bSizer6.Add (self. m_button11, 0, wx. ALL, 5) self. m_button12 = wx. button (self, wx. ID_ANY, u "9", wx. defaultPosition, wx. size (110, 60), 0) bSizer6.Add (self. m_button12, 0, wx. ALL, 5) self. m_button13 = wx. button (self, wx. ID_ANY, u "*", wx. defaultPosition, wx. size (110, 60), 0) bSizer6.Add (self. m_button13, 0, wx. ALL, 5) bSizer1.Add (bSizer6, 0, wx. EXPAND, 5) bSizer7 = wx. boxSizer (wx. HORIZONTAL) self. m_button15 = wx. button (self, wx. ID_ANY, u "4", wx. defaultPosition, wx. size (110, 60), 0) bSizer7.Add (self. m_button15, 0, wx. ALL, 5) self. m_button16 = wx. button (self, wx. ID_ANY, u "5", wx. defaultPosition, wx. size (110, 60), 0) bSizer7.Add (self. m_button16, 0, wx. ALL, 5) self. m_button17 = wx. button (self, wx. ID_ANY, u "6", wx. defaultPosition, wx. size (110, 60), 0) bSizer7.Add (self. m_button17, 0, wx. ALL, 5) self. m_button18 = wx. button (self, wx. ID_ANY, u "-", wx. defaultPosition, wx. size (110, 60), 0) bSizer7.Add (self. m_button18, 0, wx. ALL, 5) bSizer1.Add (bSizer7, 0, wx. EXPAND, 5) bSizer34 = wx. boxSizer (wx. HORIZONTAL) self. m_button140 = wx. button (self, wx. ID_ANY, u "1", wx. defaultPosition, wx. size (110, 60), 0) bSizer34.Add (self. m_button140, 0, wx. ALL, 5) self. m_button141 = wx. button (self, wx. ID_ANY, u "2", wx. defaultPosition, wx. size (110, 60), 0) bSizer34.Add (self. m_button141, 0, wx. ALL, 5) self. m_button142 = wx. button (self, wx. ID_ANY, u "3", wx. defaultPosition, wx. size (110, 60), 0) bSizer34.Add (self. m_button142, 0, wx. ALL, 5) self. m_button143 = wx. button (self, wx. ID_ANY, u "+", wx. defaultPosition, wx. size (110, 60), 0) bSizer34.Add (self. m_button143, 0, wx. ALL, 5) bSizer1.Add (bSizer34, 0, wx. EXPAND, 5) bSizer35 = wx. boxSizer (wx. HORIZONTAL) self. m_button145 = wx. button (self, wx. ID_ANY, u "0", wx. defaultPosition, wx. size (110, 60), 0) bSizer35.Add (self. m_button145, 0, wx. ALL, 5) self. m_button148 = wx. button (self, wx. ID_ANY, u ". ", wx. defaultPosition, wx. size (110, 60), 0) bSizer35.Add (self. m_button148, 0, wx. ALL, 5) self. m_button149 = wx. button (self, wx. ID_ANY, u "+/-", wx. defaultPosition, wx. size (110, 60), 0) bSizer35.Add (self. m_button149, 0, wx. ALL, 5) self. m_button150 = wx. button (self, wx. ID_ANY, u "=", wx. defaultPosition, wx. size (110,600), 0) self. m_button150.SetMinSize (wx. size (110, 60) bSizer35.Add (self. m_button150, 0, wx. ALL, 5) bSizer1.Add (bSizer35, 0, wx. EXPAND, 5) self. setSizer (bSizer1) self. layout () self. centre (wx. BOTH) # Connect Events self. m_button1.Bind (wx. EVT_BUTTON, self. m_button1OnButtonClick) self. m_button2.Bind (wx. EVT_BUTTON, self. m_button2OnButtonClick) self. m_button3.Bind (wx. EVT_BUTTON, self. m_button3OnButtonClick) self. m_button4.Bind (wx. EVT_BUTTON, self. m_button4OnButtonClick) self. m_button10.Bind (wx. EVT_BUTTON, self. m_button10OnButtonClick) self. m_button11.Bind (wx. EVT_BUTTON, self. m_button11OnButtonClick) self. m_button12.Bind (wx. EVT_BUTTON, self. m_button12OnButtonClick) self. m_button13.Bind (wx. EVT_BUTTON, self. m_button13OnButtonClick) self. m_button15.Bind (wx. EVT_BUTTON, self. m_button15OnButtonClick) self. m_button16.Bind (wx. EVT_BUTTON, self. m_button16OnButtonClick) self. m_button17.Bind (wx. EVT_BUTTON, self. m_button17OnButtonClick) self. m_button18.Bind (wx. EVT_BUTTON, self. m_button18OnButtonClick) self. m_button140.Bind (wx. EVT_BUTTON, self. m_button140OnButtonClick) self. m_button141.Bind (wx. EVT_BUTTON, self. m_button141OnButtonClick) self. m_button142.Bind (wx. EVT_BUTTON, self. m_button142OnButtonClick) self. m_button143.Bind (wx. EVT_BUTTON, self. m_button143OnButtonClick) self. m_button145.Bind (wx. EVT_BUTTON, self. m_button145OnButtonClick) self. m_button148.Bind (wx. EVT_BUTTON, self. m_button148OnButtonClick) self. m_button149.Bind (wx. EVT_BUTTON, self. m_button149OnButtonClick) self. m_button150.Bind (wx. EVT_BUTTON, self. m_button150OnButtonClick) def _ del _ (self): pass # Virtual event handlers, overide them in your derived class def m_button1OnButtonClick (self, event): result = self. m_textCtrl1.GetValue () result = result [:-1] self. m_textCtrl1.SetValue (result) def m_button2OnButtonClick (self, event): result = self. m_textCtrl1.GetValue () result = ''self. m_textCtrl1.SetValue (result) def m_button3OnButtonClick (self, event): result = self. m_textCtrl1.GetValue () result = int (result) result = math. sqrt (result) self. m_textCtrl1.SetValue (str (result) def m_button4OnButtonClick (self, event): result = self. m_textCtrl1.GetValue () result = result + '/'self. m_textCtrl1.SetValue (result) def m_button10OnButtonClick (self, event): result = self. m_textCtrl1.GetValue () result = result + '7' self. m_textCtrl1.SetValue (result) def m_button11OnButtonClick (self, event): result = self. m_textCtrl1.GetValue () result = result + '8' self. m_textCtrl1.SetValue (result) def m_button12OnButtonClick (self, event): result = self. m_textCtrl1.GetValue () result = result + '9' self. m_textCtrl1.SetValue (result) def m_button13OnButtonClick (self, event): result = self. m_textCtrl1.GetValue () result = result + '*' self. m_textCtrl1.SetValue (result) def m_button15OnButtonClick (self, event): result = self. m_textCtrl1.GetValue () result = result + '4' self. m_textCtrl1.SetValue (result) def m_button16OnButtonClick (self, event): result = self. m_textCtrl1.GetValue () result = result + '5' self. m_textCtrl1.SetValue (result) def m_button17OnButtonClick (self, event): result = self. m_textCtrl1.GetValue () result = result + '6' self. m_textCtrl1.SetValue (result) def m_button18OnButtonClick (self, event): result = self. m_textCtrl1.GetValue () result = result + '-' self. m_textCtrl1.SetValue (result) def m_button140OnButtonClick (self, event): result = self. m_textCtrl1.GetValue () result = result + '1' self. m_textCtrl1.SetValue (result) def m_button141OnButtonClick (self, event): result = self. m_textCtrl1.GetValue () result = result + '2' self. m_textCtrl1.SetValue (result) def m_button142OnButtonClick (self, event): result = self. m_textCtrl1.GetValue () result = result + '3' self. m_textCtrl1.SetValue (result) def m_button143OnButtonClick (self, event): result = self. m_textCtrl1.GetValue () result = result + '+ 'self. m_textCtrl1.SetValue (result) def m_button145OnButtonClick (self, event): result = self. m_textCtrl1.GetValue () result = result + '0' self. m_textCtrl1.SetValue (result) def m_button148OnButtonClick (self, event): result = self. m_textCtrl1.GetValue () result = result + '. 'self. m_textCtrl1.SetValue (result) def m_button149OnButtonClick (self, event): result = self. m_textCtrl1.GetValue () result =-int (result) self. m_textCtrl1.SetValue (str (result) def m_button150OnButtonClick (self, event): self. m_textCtrl1.SetValue (str (eval (self. m_textCtrl1.GetValue () app = wx. app () window = MyFrame1 (None) window. show (True) app. mainLoop ()

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.