龙空技术网

用 Python Tkinter 代码,轻松创建一个计算器,你也来试试吧!

unclemark好运英语 63

前言:

此时咱们对“python制作简单计算器”大概比较珍视,兄弟们都需要学习一些“python制作简单计算器”的相关知识。那么小编也在网摘上网罗了一些有关“python制作简单计算器””的相关文章,希望兄弟们能喜欢,各位老铁们快快来学习一下吧!

本文是号主在头条号平台上(Mark学Python)的Python代码展示,之所以选择用Python Tkinter模块创建一个简单的计算器,用于加减乘除,是因为,在号主的其他平台上,这个代码被N多人收藏和点赞,希望我们头条的粉丝,更加热情,更能帮助号主转发和分享。

先看一下代码运行后的截图效果图:

用Python中的Tkinter代码创建的简单计算器面板

以下是代码全文:

from tkinter import *win = Tk()win.title("Mark's calculator")win.geometry("360x500")en1 = Entry(win,  bg="powder blue",  bd=30, font=("Arial", 20, "bold"))en1.grid(row=0, column=0, rowspan=2, columnspan=4)btn1 = Button(win, text=" 1 ", font=("Arial", 30, "bold"))btn1.grid(row=2,column=0)btn2 = Button(win, text=" 2 ", font=("Arial", 30, "bold"))btn2.grid(row=2,column=1)btn3 = Button(win, text=" 3 ", font=("Arial", 30, "bold"))btn3.grid(row=2,column=2)btn4 = Button(win, text=" 4 ", font=("Arial", 30, "bold"))btn4.grid(row=3,column=0)btn5 = Button(win, text=" 5 ", font=("Arial", 30, "bold"))btn5.grid(row=3,column=1)btn6 = Button(win, text=" 6 ", font=("Arial", 30, "bold"))btn6.grid(row=3,column=2)btn7 = Button(win, text=" 7 ", font=("Arial", 30, "bold"))btn7.grid(row=4,column=0)btn8 = Button(win, text=" 8 ", font=("Arial", 30, "bold"))btn8.grid(row=4,column=1)btn9 = Button(win, text=" 9 ", font=("Arial", 30, "bold"))btn9.grid(row=4,column=2)btn0 = Button(win, text=" 0 ", font=("Arial", 30, "bold"))btn0.grid(row=5,column=0)btnadd = Button(win, text=" + ", font=("Arial", 30, "bold"))btnadd.grid(row=2,column=3)btnminus = Button(win, text=" -  ", font=("Arial", 30, "bold"))btnminus.grid(row=3,column=3)btntimes = Button(win, text=" *  ", font=("Arial", 30, "bold"))btntimes.grid(row=4,column=3)btndiv = Button(win, text="  /  ", font=("Arial", 30, "bold"))btndiv.grid(row=5,column=3)btnblank = Button(win, text=" r  ", font=("Arial", 30, "bold"))btnblank.grid(row=5,column=2)btnclr = Button(win, text=" c ", font=("Arial", 30, "bold"))btnclr.grid(row=5,column=0)btneql = Button(win, text=" = ", font=("Arial", 30, "bold"))btneql.grid(row=5,column=1)btnsign = Button(win, text="  Mark 学 Python  ", font=("Arial", 30, "bold"))btnsign.grid(row=6,column=0, columnspan=4)win.mainloop()

今天时间有些紧,原定于系统介绍讲解这些代码的计划,改为根据粉丝读者的意愿,下一次是直接分享视频还是继续文字解释计算部分。另外,面板的排列还有进一步改善的空间,有些数字是号主的经验数字,请特别注意。如果读者继续美化这个计算器面板,可以自行尝试。

另外,征求读者意见,我们是不是开始介绍初学者最感兴趣的,特别是小朋友最感兴趣的画图?如果互动点赞分享多了,号主自然会安排turtle的内容。

标签: #python制作简单计算器