- 39
- 0
import tkinter as tk
window = tk.Tk()
window.title('计算器')
window.geometry('360x435')
window.attributes("-alpha", 0.95)
window.resizable(0, 0)#窗口大小固定,不能缩放
var = tk.StringVar()
frm_1 = tk.Frame(window, width=360, height=115, bg='CadetBlue').place(x=0, y=0, anchor=tk.NW)#数字显示区
frm_2 = tk.Frame(window, width=270, height=240, bg='DarkSeaGreen').place(x=0, y=115, anchor=tk.NW)#数字键盘
frm_3 = tk.Frame(window, width=90, height=320, bg='Beige').place(x=270, y=115, anchor=tk.NW)#加减乘除
frm_4 = tk.Frame(window, width=270, height=80, bg='CadetBlue').place(x=0, y=355, anchor=tk.NW)#不可循环输出的
var_result = tk.StringVar()
var_dian=tk.StringVar()
var_dian.set('.')
def name(u):
u='var'+str(u)
return u
#数字显示区
I = tk.Entry(frm_1,textvariable=var_result,font=('Arial',40),bg='grey')
I.place(x=0,y=0,width=360,height=115)
#获取数字显示区的文字
#函数部分
#计算结果的
def show_result():
result = I.get()
print(eval(result))
def delete():
f.delete(1.0, tk.END)
def get():
pass
num=1
#数字键盘,可循环显示的
for j in range(3):
for i in range(3):
m=0+(i)*90
n=115+(j)*80
b=tk.Button(frm_2,text=num,bg='WhiteSmoke',font=('Arial','20'),command=get)
b.place(x=m,y=n,width=90,height=80)
num=num+1
#数字键盘,不可循环显示的
v=0
a=tk.Button(frm_4,textvariable=var_dian,bg='Gainsboro',font=('20')).place(x=0,y=355,width=90,height=80)
b=tk.Button(frm_4,text='=',bg='Gainsboro',font=('20'),command=show_result).place(x=180,y=355,width=90,height=80)
f=tk.Button(frm_4,text='0',bg='WhiteSmoke',font=('Arial','20')).place(x=90,y=355,width=90,height=80)
#加减乘除
q=0
for p in ['+','-','*','/']:
e=tk.Button(frm_3,text=p,bg='Gainsboro',font=('20')).place(x=270,y=115+q*80,width=90,height=80)
q=q+1
window.mainloop() 0
打赏
收藏
点击回答
- 共 0 条
- 全部回答
-
你是我预订的人i 普通会员 1楼
在Tkinter中,你可以使用
id()方法来获取组件的名称。例如,如果你想获取按下某个Button时显示的文本,你可以这样做:```python import tkinter as tk
root = tk.Tk()
button1 = tk.Button(root, text="Button 1") button2 = tk.Button(root, text="Button 2") button3 = tk.Button(root, text="Button 3")
button1.bind("
", function=lambda x: button1.config(text=x.text)) button2.bind(" ", function=lambda x: button2.config(text=x.text)) button3.bind(" ", function=lambda x: button3.config(text=x.text)) root.mainloop() ```
在这个例子中,我们创建了三个Button,然后绑定了
<Button-1>事件处理程序。当用户按下按钮时,config()方法会被调用,该方法会改变按钮的文本。
更多回答
网站公告
- 扫一扫访问手机版
回答动态

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器更新之后。服务器里面有部分玩家要重新创建角色是怎么回事啊?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题函数计算不同地域的是不能用内网吧?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题ARMS可以创建多个应用嘛?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题在ARMS如何申请加入公测呀?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题前端小程序接入这个arms具体是如何接入监控的,这个init方法在哪里进行添加?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器刚到期,是不是就不能再导出存档了呢?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器的游戏版本不兼容 尝试更新怎么解决?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器服务器升级以后 就链接不上了,怎么办?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器转移以后服务器进不去了,怎么解决?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器修改参数后游戏进入不了,是什么情况?预计能赚取 0积分收益
- 回到顶部
- 回到顶部
