首页 > 微信 > 详细

python,图形界面编程,tkinter,实现一个最简单的加法计算器的图形界面小程序

时间:2020-03-19 21:17:43      阅读:323      评论:0      收藏:0      [点我收藏+]
from tkinter import *
def Calculate():
    a1 = int(text1.get(‘1.0‘, END))  # 从行首取到行尾
    a2 = int(text2.get(‘1.0‘, END))
    a3 = a1 + a2
    text3.delete(‘1.0‘, END)
    text3.insert(INSERT, a3)

root = Tk()
root.title(‘myTitle‘)
label1 = Label(root, text = ‘First Number:‘)
label1.grid(row = 0, column = 0)
text1 = Text(root, width = 30, height = 1)
text1.grid(row= 1, column = 0)
label2 = Label(root, text = ‘Second Number:‘)
label2.grid(row = 2, column = 0)
text2 = Text(root, width = 30, height = 1)
text2.grid(row = 3, column = 0)
label3 = Label(root, text = ‘Result:‘)
label3.grid(row = 4, column = 0)
text3 = Text(root, width = 30, height = 1)
text3.grid(row = 5, column = 0)
button1 = Button(root, text = ‘Calculate‘, command = Calculate)
button1.grid(row = 6, column = 0)
mainloop()

  运行结果显示:

技术分享图片

 

 这是最简单的一个利用tkinter包实现的小程序, 实现了输入数据,计算求和并显示计算结果的功能。

python,图形界面编程,tkinter,实现一个最简单的加法计算器的图形界面小程序

原文:https://www.cnblogs.com/iceberg710815/p/12527012.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!