In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
Import tkinter# defines calculator class class Calc: # initialization magic method def _ _ init__ (self): # initialization common attribute # defines a list for storing calculated strings self.operationList = [] # defines operation tag determination Whether the operational symbol self.isOper = False # initialization interface self.initWindows () # is entered or not. Change by keyboard color method def changeBg (self Evt): evt.widget ['bg'] =' cyan' # restore the keyboard color method def backBg (self,evt): evt.widget ['bg'] =' lightgray' # numeric button operation method def buttonAction (self Number): # determines whether the user presses the operation button if self.isOper = = True: # the number self.num.set (number) # after the operator is displayed on the interface the operation flag resets self.isOper = False else: # No ammonium operation button # determine whether the original interface number is 0 existNumber = self.num.get () if existNumber = = '0operations: # if the initial number in the interface If the initial data is 0, get the user input data and display self.num.set (number) else: # if the initial data in the interface is not 0, accumulate the characters self.num.set (self.num.get () + number) # Operation button operation method def operation (self OpFlag): # the operation flag is set to true self.isOper = True # to get the number that exists in the interface and write the list self.operationList.append (self.num.get ()) # the current operation symbol will not be written in the previous step, it needs to be written to self separately. OperationList.append (opFlag) # Operation method def getResult (self): # add the numbers in the current interface to the calculation list self.operationList.append (self.num.get ()) # start the calculation result = eval ('.join (self.operationList)) Self.num.set (result) # all empty recalculation method def clearAll (self): # interface set 0 calculation list set 0 self.num.set ('0') self.operationList.clear () # Operation flag reset self.isOper = False # implement the backspace key method def backSpace (self): # get the current display digit length strLength = len (self.num.get ()) # if there is a number if strLength > 1: # Delete the last word in the string PresentStr = self.num.get () presentStr = presentStr [: strLength-1] self.num.set (presentStr) else: self.num.set ('0') # positive and negative sign implementation method def pm (self): presentStr = Self.num.get () # implements the addition and removal of the negative sign if presentStr [0] = ='-': self.num.set (string [1:]) # the original string must not start with the-sign and 0 elif presentStr [0] not in ('-' '0'): self.num.set (' -'+ presentStr) # Interface layout method def initWindows (self): # generate main window Custom window size root = tkinter.Tk () root.minsize (400500) root.title ('Micro hard Calculator') # generate the variable self.num = tkinter.StringVar () self.num.set (0) # the operation result output position result = tkinter.Label (root) Width=20,height=2,bg='white',bd=10,anchor='e',font= ('Song style', 50), textvariable=self.num) result.place (relx=0,rely=0,relwidth=1.0 Relheight=0.4) # # the following is the key part # # buttonCE = tkinter.Button (root,text='CE',bg='lightgray',command = self.clearAll) buttonCE.place (relx=0,rely=0.4,relwidth=0.25 Relheight=0.1) # bind button to generate mouse discoloration effect buttonCE.bind (', self.changeBg) buttonCE.bind (', self.backBg) buttonC = tkinter.Button (root,text='C',bg='lightgray',command = self.clearAll) buttonC.place (relx=0.25,rely=0.4,relwidth=0.25) Relheight=0.1) # bind button to generate mouse discoloration effect buttonC.bind (', self.changeBg) buttonC.bind (', self.backBg) buttonDel = tkinter.Button (root,text=')
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.