问题描述
import tkinter as tk
root = tk.Tk()
root.title("skaiciuotuvas")
e = tk.Entry(root,width=35,borderwidth=5)
e.grid(row=0,column=0,columnspan=3,padx=10,pady=15)
e.insert(0,0)
按钮动作功能
def button_click(number):
e.delete(0,"end")
current = e.get()
e.delete(0,"end")
e.insert(0,str(current) + str(number))
def button_clear():
e.delete(0,"end")
这是一个简单的计算器,可以计算 num + num = res :需要得到 num + num + num ...etc = rez 是否可以对这段代码进行验证
def button_add():
first_number = int(e.get())
global f_num
f_num = int(first_number)
e.delete(0,"end")
是否可以只使用 def button_add(): 函数?
def button_equal():
second_number = e.get()
e.delete(0,"end")
e.insert(0,int(second_number)+ f_num)
按钮这是我的项目的规格值
button1 = tk.Button(root,text="1",padx=40,pady=20,command=lambda: button_click(-30))
button2 = tk.Button(root,text="2",command=lambda: button_click(-20))
button3 = tk.Button(root,text="3",command=lambda: button_click(-18))
button4 = tk.Button(root,text="4",command=lambda: button_click(-16))
button5 = tk.Button(root,text="5",command=lambda: button_click(-15))
button6 = tk.Button(root,text="6",command=lambda: button_click(-12))
button7 = tk.Button(root,text="7",command=lambda: button_click(-7))
button8 = tk.Button(root,text="8",command=lambda: button_click(8))
button9 = tk.Button(root,text="9",command=lambda: button_click(9))
button10 = tk.Button(root,text="10",padx=37,command=lambda: button_click(10))
button_15 = tk.Button(root,text="-15",padx=34,command=lambda: button_click(-15))
button_add = tk.Button(root,text="+",padx=39,command= button_add)
button_equal = tk.Button(root,text="=",padx=86,command= button_equal)
button_clear = tk.Button(root,text="C",command=button_clear)
#put 按钮在屏幕上
button2.grid(row=3,column=2)
button3.grid(row=3,column=1)
button4.grid(row=3,column=0)
button5.grid(row=2,column=2)
button6.grid(row=2,column=1)
button7.grid(row=2,column=0)
button8.grid(row=1,column=2)
button9.grid(row=1,column=1)
button10.grid(row=1,column=0)
button_add.grid(row=4,column=2)
button_15.grid(row=5,column=0)
button1.grid(row=4,column=1)
button_equal.grid(row=5,column=1,columnspan=2)
button_clear.grid(row=4,column=0)
root.mainloop()
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)