1、2、3などのボタンを使って簡単な電卓を作ったのですが、1または2などのボタンのテキストを電卓の画面に置くことができません。あなたたちは私にいくつかのヒントを与える場合、それは非常に参考になる ..電卓の画面にボタンのテキストを表示する方法
from tkinter import *
root = Tk()
buttons = '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '+', '-'
def calc(value):
res = num.get()
res = res + " " + value
res = str(eval(res))
num.set(res)
num = StringVar()
rows = 1
col = 0
ent = Entry(root, textvariable = num, background = "#D0F3F5", border = 2, width = 50)
ent.bind('<FocusOut>')
ent.grid(row = 0 , column = 0, columnspan = 4, ipadx = 5, ipady = 5)
Button(root, text = '=', width = 45, command = calc).grid(column = 0, row = 5, columnspan = 4)
for button in buttons:
button = Button(root,width = 10, text = button, command = lambda: calc(button))
#button.bind('<Button-1>', lambda e: screen(button))
button.grid(row = rows, column = col, sticky = "W E")
button['relief']="groove"
col = col + 1
if col == 4:
rows = rows + 1
col = 0
if rows > 6:
break
root.mainloop()
:
にあなたのコードの結果に、これらすべてを適用します。 'command = calc'これはどのように使用されますか? 'for button in button:button = Button(..)'ここでは同じ名前を使用します。 'res +" "+ value" 'str(eval(res))'あなたは何を評価しようとしていますか? –