本文整理汇总了Python中calculator.Calculator.key_pressed方法的典型用法代码示例。如果您正苦于以下问题:Python Calculator.key_pressed方法的具体用法?Python Calculator.key_pressed怎么用?Python Calculator.key_pressed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类calculator.Calculator
的用法示例。
在下文中一共展示了Calculator.key_pressed方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Tk
# 需要导入模块: from calculator import Calculator [as 别名]
# 或者: from calculator.Calculator import key_pressed [as 别名]
from tkinter import Entry
from tkinter import Button
from calculator import Calculator
root = Tk()
root.title("Calculator")
frame = Frame(root)
frame.grid()
display = Entry(frame,bd=20, insertwidth=1,font=30)
display.config(state="disabled")
display.grid(row = 0, column = 0, columnspan = 5)
calculator = Calculator(display)
buttons = ["1","2","3","/-","<",
"4","5","6","*","/",
"7","8","9","+","-",
".","0","CE","C","="]
i=0
button = []
for rows in range (1,5):
for columns in range(5):
button.append(Button(frame,text=buttons[i],padx=16,pady=16,bd=6,fg="black",command=lambda x=i: calculator.key_pressed(buttons[x])))
button[i].grid(row = rows, column = columns)
i+=1
root.mainloop()