Calculator written with 40 lines of pythoncode
Occasionally writing something in a script is also good.
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 ("
", ButtonCallBack) showText =" () "for I in range (2): www.bkjia.com B = Button (root, text = showText [I], width = 7) B. grid (row = 6, column = 2 + I) B. bind ("
", ButtonCallBack) B = Button (root, text =" = ") B. grid (row = 6, columnspan = 2, sticky =" we ") B. bind ("
", ButtonCallBack) root. mainloop ()