结果呈现
实现了加、减、乘、除运算,并可以进行清除及删除操作。
代码
from tkinter import *
Calculator = Tk()
Calculator.geometry('320x195+400+120')
Calculator.title('计算器示例')
Formula = '' # 记录算式
digit = 0 # 用于记算式的字符数
OutputNumber = 0 # 运算结果
# 定义函数方法
def input1():
global Formula
global digit
Inputentry.insert(END,'1')
Formula += '1'
digit += 1
def input2():
global Formula
global digit
digit += 1
Inputentry.insert(END,'2')
Formula += '2'
def input3():
global Formula
global digit
digit += 1
Inputentry.insert(END,'3')
Formula += '3'
def input4():
global Formula
global digit
digit += 1
Inputentry.insert(END,'4')
Formula += '4'
def input5():
global Formula
global digit
digit += 1
Inputentry.insert(END,'5')
Formula += '5'
def input6():
global Formula
global digit
digit += 1
Inputentry.insert(END,'6')
Formula += '6'
def input7():
global Formula
global digit
digit += 1
Inputentry.insert(END,'7')
Formula += '7'
def input8():
global Formula
global digit
digit += 1
Inputentry.insert(END,'8')
Formula += '8'
def input9