Python uses only 40 lines of code to write a calculator instance, and python40 lines
This example describes a calculator written in Python with only 40 lines of code. We will share this with you for your reference. The details are as follows:
:
Code:
From tkinter import * reset = Truedef buttonCallBack (event): global label global reset num = event. widget ['text'] if num = 'C': label ['text'] = "0" return if num in "= ": label ['text'] = str (eval (label ['text']) reset = True return s = label ['text'] if s = '0' or reset = True: s = "" reset = False label ['text'] = s + num # Main Window root = Tk () root. wm_title ("Calculator") # display column 1 label = Label (root, text = "0", background = "white", anchor = "e ") label ['width'] = 35 label ['height'] = 2label. grid (row = 1, columnspan = 4, sticky = W) # button showText = "789/456 * 123-0.C +" for I in range (4): for j in range (4 ): B = Button (root, text = showText [I * 4 + j], width = 7) B. grid (row = I + 2, column = j) B. bind ("<button-1>", buttonCallBack) showText = "()" for I in range (2): www.jb51.net B = Button (root, text = showText [I], width = 7) B. grid (row = 6, column = 2 + I) B. bind ("<button-1>", buttonCallBack) B = Button (root, text = "=") B. grid (row = 6, columnspan = 2, sticky = "we") B. bind ("<button-1>", buttonCallBack) root. mainloop () </button-1> </button-1> </button-1>
PS: Here are some recommended computing tools for your reference:
Calculation tool for online mona1 functions (equations:
Http://tools.jb51.net/jisuanqi/equ_jisuanqi
Scientific calculator online use _ advanced calculator online computing:
Http://tools.jb51.net/jisuanqi/jsqkexue
Online calculator _ standard calculator:
Http://tools.jb51.net/jisuanqi/jsq