python gui
2021/12/11 17:19:51
本文主要是介绍python gui,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
代码:
# encoding:utf-8 import tkinter as tk root = tk.Tk() root.title("Small Calculator") root.geometry('500x300') var1 = tk.DoubleVar() label1 = tk.Label(text="第一个数字", width=20, height=2) label1.pack() entry1 = tk.Entry(width=20) entry1.pack() var2 = tk.StringVar() label2 = tk.Label(text="符号", width=20, height=2) label2.pack() entry2 = tk.Entry(width=20) entry2.pack() var3 = tk.DoubleVar() label3 = tk.Label(text="第二个数字", width=20, height=2) label3.pack() entry3 = tk.Entry(width=20) entry3.pack() var4 = tk.DoubleVar() label4 = tk.Label(text="结果", width=20, height=2) label4.pack() label5 = tk.Label(textvar=var4, width=30, height=1,) label5.pack() def clickFun(): global var1 global var2 global var3 global var4 va11 = int(entry1.get()) var2 = entry2.get() var3 = int(entry3.get()) if var2 == '+': var4.set(int(va11+var3)) elif var2 == '-': var4.set(int(va11-var3)) elif var2 == '': var4.set(int(va11*var3)) elif var2 == '/': if var3 == 0: var4.set("请重新输入数据") else: var4.set(int(va11/var3)) else: var4.set("运算符出错,请重新输入数据") button1 = tk.Button(text="完成" ,width=10, height=2, command=clickFun) button1.pack() root.mainloop()
这篇关于python gui的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-14获取参数学习:Python编程入门教程
- 2024-11-14Python编程基础入门
- 2024-11-14Python编程入门指南
- 2024-11-13Python基础教程
- 2024-11-12Python编程基础指南
- 2024-11-12Python基础编程教程
- 2024-11-08Python编程基础与实践示例
- 2024-11-07Python编程基础指南
- 2024-11-06Python编程基础入门指南
- 2024-11-06怎么使用python 计算两个GPS的距离功能-icode9专业技术文章分享