EasyGui设计一个简单的计算器

计算器功能:两个整数的加减乘除。刚刚开始学所以功能很简单。
#设计一个计算器,用于两个数的加减乘除,并显示结果
#要用到easygui实现界面交互

#设计一个计算器,用于两个数的加减乘除,并显示结果
#要用到easygui实现界面交互


import easygui as sc
title = "Simple_Calculator"
end_sign = 1#结束判断标志
result = 0#默认结果为0
sc.msgbox(msg='欢迎使用', title=title, image='calculator.gif', ok_button='开始')
# 欢迎界面 文件夹中要有calculator.gif命名的图片

while end_sign:
    first_number = sc.integerbox(msg='输入第一个数', title=title,lowerbound=-999999, upperbound=999999)
    if first_number is None:#判断要不要继续
        break

    operation = sc.buttonbox(msg='选择运算符号', title=title, choices=['+', '-', '*', '/'])
    if operation is None:#判断要不要继续
        break

    second_number = sc.integerbox(msg='输入第二个数', title=title,lowerbound=-999999, upperbound=999999)
    if second_number is None:#判断要不要继续
        break


    if operation == '+':
        result = first_number + second_number
    if operation == '-':
        result = first_number - second_number
    if operation == '*':
        result = first_number * second_number
    if operation == '/':
        result = first_number / second_number
    result = "计算结果:"+str(first_number)+operation+str(second_number)+'='+str(result)  #运算过程
    end_sign = sc.indexbox(msg=result, title=title, choices=['结束','继续'] )
    # 显示计算过程和结果结果,并判断要不要继续,点”结束“ end_sign赋值为0,退出程序。
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值