1 Star 0 Fork 0

vividoner/calculator

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
button.py 1.24 KB
一键复制 编辑 原始数据 按行查看 历史
vividoner 提交于 2023-12-01 20:39 . 第一次提交 计算器作品
import tkinter as tk
def create_button(win, color, font):
btns = []
op = ['C', '←', '÷', '×', '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '=', '0', '.']
row = 2
for i in range(len(op)):
if '0' <= op[i] <= '9' or op[i] == '.':
c = color['ncolor']
ac = color['nbcolor']
else:
c = color['ocolor']
ac = color['obcolor']
# 创建按钮
btn = tk.Button(
win,
text=op[i],
width=5,
font=font,
relief=tk.FLAT,
bg=c,
activebackground=ac
)
if op[i] == '=':
btn.config(height=3)
if op[i] == '0':
btn.config(width=12)
# 布局
row_span = 1
column_span = 1
# 设置行列
if i % 4 == 0:
row += 1
col = i % 4 + 1
# 处理特殊按钮
if row == 7 and col == 2:
col += 1
if row == 6 and col == 4:
row_span = 2
if row == 7 and col == 1:
column_span = 2
# 按钮布局
btn.grid(row=row, column=col, padx=4, pady=2, rowspan=row_span, columnspan=column_span)
btns.append(btn)
return btns
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/Zvivi/calculator.git
git@gitee.com:Zvivi/calculator.git
Zvivi
calculator
calculator
master

搜索帮助