学习记录:python tkinter写一个计算器的demo

import tkinter
import tkinter.messagebox
window = tkinter.Tk()
window.title('demo_0.1')
window.geometry('200x250')

e1 = tkinter.Entry(window)
e1.place(x = 0, y=0, width=200,height=50)

#第一排
button_a1 = tkinter.Button(window, text='/', font=('microsoft yahei', 13, 'bold', 'italic'),borderwidth=0.5)
button_a1.place(x=0, y=50, width=50, height=50)

button_a2 = tkinter.Button(window, text='x', font=('microsoft yahei', 13, 'bold', 'italic'),borderwidth=0.5)
button_a2.place(x=50, y=50, width=50, height=50)

button_a3 = tkinter.Button(window, text='-', font=('microsoft yahei', 20, 'bold', 'italic'),borderwidth=0.5)
button_a3.place(x=100, y=50, width=50, height=50)

button_a4 = tkinter.Button(window, text='+', font=('microsoft yahei', 13, 'bold', 'italic'),borderwidth=0.5)
button_a4.place(x=150, y=50, width=50, height=50)

#第二排
button_b1 = tkinter.Button(window, text='7', font=('microsoft yahei', 10, 'bold', 'italic'),borderwidth=0.5)
button_b1.place(x=0, y=100, width=50, height=50)

button_b2 = tkinter.Button(window, text='6', font=('microsoft yahei', 10, 'bold', 'italic'),borderwidth=0.5)
button_b2.place(x=50, y=100, width=50, height=50)

button_b3 = tkinter.Button(window, text='1', font=('microsoft yahei', 10, 'bold', 'italic'),borderwidth=0.5)
button_b3.place(x=100, y=100, width=50, height=50)

button_b4 = tkinter.Button(window, text='0', font=('microsoft yahei', 10, 'bold', 'italic'),borderwidth=0.5)
button_b4.place(x=150, y=100, width=50, height=50)

#第三排
button_c1 = tkinter.Button(window, text='8', font=('microsoft yahei', 10, 'bold', 'italic'),borderwidth=0.5)
button_c1.place(x=0, y=150, width=50, height=50)

button_c2 = tkinter.Button(window, text='5', font=('microsoft yahei', 10, 'bold', 'italic'),borderwidth=0.5)
button_c2.place(x=50, y=150, width=50, height=50)

button_c3 = tkinter.Button(window, text='2', font=('microsoft yahei', 10, 'bold', 'italic'),borderwidth=0.5)
button_c3.place(x=100, y=150, width=50, height=50)

button_c4 = tkinter.Button(window, text='c', font=('microsoft yahei', 15, 'bold', 'italic'),borderwidth=0.5)
button_c4.place(x=150, y=150, width=50, height=50)

#第四排
button_d1 = tkinter.Button(window, text='9', font=('microsoft yahei', 10, 'bold', 'italic'),borderwidth=0.5)
button_d1.place(x=0, y=200, width=50, height=50)

button_d2 = tkinter.Button(window, text='4', font=('microsoft yahei', 10, 'bold', 'italic'),borderwidth=0.5)
button_d2.place(x=50, y=200, width=50, height=50)

button_d3 = tkinter.Button(window, text='3', font=('microsoft yahei', 10, 'bold', 'italic'),borderwidth=0.5)
button_d3.place(x=100, y=200, width=50, height=50)

button_d4 = tkinter.Button(window, text='=', font=('microsoft yahei', 15, 'bold', 'italic'),borderwidth=0.5)
button_d4.place(x=150, y=200, width=50, height=50)

window.mainloop()

效果图

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_26086231/article/details/113058410
今日推荐