代码拉取完成,页面将自动刷新
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
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。