Sometimes it's nice to write something with a script .
Code
From Tkinter import *reset=truedef buttoncallback (Event): Global label Global Reset num=event.widget[' text '] I F 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") #显示栏1label =label (root,text= "0", background= "white", anchor= "E") label[' Width ']=35label[' height ']=2label.grid (row=1,columnspan=4,sticky=w) #按钮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): 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 ()
A calculator written in Python40 line code