import tkinter
import tkinter.font
class Calculator(object):
def __init__(self):
self.all_press_lists = []
self.is_press = False
self.is_press_num = False
self.root = tkinter.Tk()
self.result = tkinter.StringVar() # 显示输入的数字及结果
self.record = tkinter.StringVar() # 显示计算过程
def main(self):
self.root.minsize(300, 550)
self.root.title('计算器')
input_bg = "#393943"
num_fg = "#DCDCDC"
btn_fg = "#909194"
btn_bg = "#22222C"
btn_w = 75
btn_h = 70
my_font = tkinter.font.Font(family='微软雅黑', size=20) # 设置字体
self.result.set(0)
self.record.set('')
# 显示版
label = tkinter.Label(self.root, font=my_font, bg=input_bg, bd='9', fg=num_fg, anchor='se',
textvariable=self.record)
label.place(width=300, height=120)
label2 = tkinter.Label(self.root, font=my_font, bg=input_bg, bd='9', fg=num_fg, anchor='se',
textvariable=self.result)
label2.place(y=120, width=300, height=80)
# 第一行
btn_ac = tkinter.Button(self.root, text='c', font=my_font, bg=btn_bg, fg=btn_fg, bd=0,
command=lambda: self.press_compute('AC'))
btn_ac.place(x=btn_w * 0, y=200 + btn_h * 0, width=btn_w, height=btn_h)
btn_back = tkinter.Button(self.root, text='←', font=my_
用python实现计算器
最新推荐文章于 2024-08-02 17:05:01 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)