Deqin -德钦牌计算器

import tkinter as tk

p = tk.Tk()
p.geometry("280x500")
p.title("德钦计算器")

label1 = tk.Label(
    p,
    font=('Arial', 20),
    bg="#8A2BE2",
    fg="#000000",
    bd=9,
    anchor='se',  # 船锚  north北  south南  west 西 east 东
    text="计算结果"
)
label1.place(x=0, y=0, width=280, height=170)
label2 = tk.Label(
    p,
    font=('Arial', 20),
    bg="#8A2BF5",
    fg="#000000",
    bd=9,
    anchor='se',  # 船锚  north北  south南  west 西 east 东
    text="计算公式"
)
label2.place(x=0, y=170, width=280, height=60)


def btn(t, x, y, color="#0000FF",width = 70,height = 55):
    btn7 = tk.Button(
        p,
        text=t,
        font=('Arial', 20),
        fg=color,
        bd=0.5,
        command = lambda:press(t)
    )
    btn7.place(x=x, y=y, width=width, height=height)


# 第一行按钮
btn('AC', 0, 230, color="#FF00FF")
btn('DEL', 70, 230, color="#FF00FF")
btn('/', 140, 230, color="#6A5ACD")
btn('*', 210, 230, color="#6A5ACD")

# 第二行按钮
btn('7', 0, 285)
btn('8', 70, 285)
btn('9', 140, 285)
btn('-', 210, 285, color="#6A5ACD")
# 第三行按钮
btn('4', 0, 340)
btn('5', 70, 340)
btn('6', 140, 340)
btn('+', 210, 340, color="#6A5ACD")
# 第四行按钮
btn('1', 0, 395)
btn('2', 70, 395)
btn('3', 140, 395)
btn('=', 210, 395, color="#6A5ACD",height=110)

# 第五行按钮
btn('%', 0, 450,width = 35)
btn('.', 35, 450,width = 35)
btn('0', 70, 450)
btn('(', 140, 450,width = 35)
btn(')', 175, 450,width = 35)





p.mainloop()

2.0

import tkinter as tk


def press(num):
    global express
    express = express + num
    label2['text'] = express


def equal():
    global express
    result = eval(express)
    label1['text'] = result


# AC是清楚功能,按按钮清楚计算公式,把表达式改成空字符串,然后再把表达式(“计算公式”)放在标签上
# sfbhvfvjeoigbjsrfndel

def AC():
    global express
    label1['text'] = ""
    label2['text'] = '大爷你再输入一次'
    express = ""


def DEL():
    global express
    express = express[0:len(express) - 1]
    label1['text'] = ""
    label2['text'] = express


def btn(t, x, y, color="#0000FF", width=70, height=55):
    btn7 = tk.Button(
        p,
        text=t,
        font=('Arial', 20),
        fg=color,
        bd=0.5,
        command=lambda: press(t)
    )
    btn7.place(x=x, y=y, width=width, height=height)


p = tk.Tk()
p.geometry("280x500")
p.title("德钦计算器")

label1 = tk.Label(
    p,
    font=('Arial', 20),
    bg="#8A2BE2",
    fg="#000000",
    bd=9,
    anchor='se',  # 船锚  north北  south南  west 西 east 东
    text="计算结果"
)
label1.place(x=0, y=0, width=280, height=170)
label2 = tk.Label(
    p,
    font=('Arial', 20),
    bg="#8A2BF5",
    fg="#000000",
    bd=9,
    anchor='se',  # 船锚  north北  south南  west 西 east 东
    text="计算公式"
)
label2.place(x=0, y=170, width=280, height=60)
# 设置表达式变量
express = ""

# 第一行按钮
# btn('AC', 0, 230, color="#FF00FF")
btnA = tk.Button(
    p,
    text='AC',
    font=('Arial', 20),
    fg="#FF00FF",
    bd=0.5,
    command=AC
)
btnA.place(x=0, y=230, width=70, height=55)

# btn('DEL', 70, 230, color="#FF00FF")
btnD = tk.Button(
    p,
    text='DEL',
    font=('Arial', 20),
    fg="#FF00FF",
    bd=0.5,
    command=DEL
)
btnD.place(x=70, y=230, width=70, height=55)

btn('/', 140, 230, color="#6A5ACD")
btn('*', 210, 230, color="#6A5ACD")

# 第二行按钮
btn('7', 0, 285)
btn('8', 70, 285)
btn('9', 140, 285)
btn('-', 210, 285, color="#6A5ACD")
# 第三行按钮
btn('4', 0, 340)
btn('5', 70, 340)
btn('6', 140, 340)
btn('+', 210, 340, color="#6A5ACD")
# 第四行按钮
btn('1', 0, 395)
btn('2', 70, 395)
btn('3', 140, 395)
# btn('=', 210, 395, color="#6A5ACD",height=110)

btnE = tk.Button(
    p,
    text='=',
    font=('Arial', 20),
    fg="#6A5ACD",
    bd=0.5,
    command=equal
)
btnE.place(x=210, y=395, width=70, height=110)

# 第五行按钮
btn('%', 0, 450, width=35)
btn('.', 35, 450, width=35)
btn('0', 70, 450)
btn('(', 140, 450, width=35)
btn(')', 175, 450, width=35)

p.mainloop()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值