I've made a simple calculator with buttons like 1, 2 ,3 and so on..but i am unable to put those button text like 1 or 2 etc onto the calculator screen. It would be very helpful if you guys give me some hints..
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()