Python tkinter实现简单加法计算器代码实例

作者:Iceberg_710815 时间:2024-01-03 03:58:49 

tkinter 是 Python 的标准 GUI 库。Python 使用 tkinter 可以快速的创建 GUI 应用程序。由于 tkinter 是内置到 python 的安装包中、只要安装好 Python 之后就能 import tkinter 库、而且 IDLE 也是用 tkinter 编写而成、对于简单的图形界面 tkinter 还是能应付自如。

代码如下


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()

运行结果显示:

Python tkinter实现简单加法计算器代码实例

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

来源:https://www.cnblogs.com/iceberg710815/p/12527012.html

标签:Python,tkinter,计算器
0
投稿

猜你喜欢

  • 忆童年!用Python实现愤怒的小鸟游戏

    2023-06-03 11:01:12
  • 详解如何用Python模拟登录淘宝

    2023-09-29 19:07:34
  • Pytorch中的backward()多个loss函数用法

    2023-11-12 00:19:21
  • 如何在Django项目中引入静态文件

    2021-10-09 11:24:52
  • ASP 错误代码

    2009-05-11 12:38:00
  • Python设计密码强度校验程序

    2022-09-29 08:37:12
  • Python数学建模PuLP库线性规划进阶基于字典详解

    2022-03-11 18:04:04
  • Django和Ueditor自定义存储上传文件的文件名

    2021-02-26 02:43:17
  • python求平均数、方差、中位数的例子

    2022-08-23 21:24:57
  • 一段Asp301重定向过程代码

    2010-05-04 16:38:00
  • 对于Python中线程问题的简单讲解

    2023-12-28 10:16:31
  • python实现过滤敏感词

    2021-02-26 04:23:17
  • Python入门教程3. 列表基本操作【定义、运算、常用函数】 <font color=red>原创</font>

    2023-07-15 13:09:19
  • Python的Flask框架中实现简单的登录功能的教程

    2023-10-26 19:18:48
  • Centos 安装 PHP7.4 和 Nginx的操作方法

    2023-10-14 01:11:55
  • PL/SQL Number数字类型函数

    2010-07-16 13:09:00
  • SQL Servr 2008空间数据应用系列四:基础空间对象与函数应用

    2011-02-23 15:01:00
  • Python 虚拟机字典dict内存优化方法解析

    2022-03-04 08:20:56
  • Python字符串类型及格式化问题

    2023-12-30 21:49:46
  • Python实战之自动发送邮件的实现

    2023-10-18 15:09:43
  • asp之家 网络编程 m.aspxhome.com