I'm making simple calculator and I've implemented all the functions except one function. As you know, dots must be used only once until the new number comes. So I want to make the (.) button disabled after used once and make it available again when I use symbol or C. I was thinking about changing the button text by using configure method.
Here's my code:
from tkinter import*
w1 = Tk()
w1.title("My Calculator")
show = Entry(w1, width=33, bg="yellow")
show.grid(row=0, column=0, columnspan=5)
btn_list = [
'7','8','9','/','C',
'4','5','6','*','',
'1','2','3','-','',
'0','.','=','+','']
index_row = 1
index_col = 0
def click(button):
if button == "=":
value = eval(show.get())
s = str(value)
show.delete(0,"end")
show.insert(END,s)
elif button=="C":
show.delete(0,"end")
else:
show.insert(END,button)
for btn_text in btn_list:
def go(k=btn_text):
click(k)
Button(
w1, text=btn_text, width=5, command=go
).grid(row=index_row, column=index_col)
index_col += 1
if index_col > 4:
index_row += 1
index_col = 0
w1.mainloop()