I am trying to develop a basic calculator and then introduce various functionalities.
I am new to Python but has been working with VB and c# for quite some time.
At present it has an Entry and three labels. I accept input from keyboard in Entry, and display on one label. Entry is hidden.
e.g. 52+56+36+45=189
User enters 52 and presses + sign
at this stage "+" is displayed on one label, 52 gets transferred to second label and Entry, first label becomes blank.
Till this stage it works properly. Now in step two when user is to enter 56 it allows allows all the keys without any validation and it stops printing output. This means that callback function is bypassed.
Any help is welcome.
import tkinter
from tkinter import *
def callback(input):
if input.isdigit() or "." in input or input == "\b":
print(input)
return True
elif "+" in input :
print(input)
svLabelOpr.set("+")
svLabelDisp.set(svLabel.get())
svLabel.set("")
svTxt.set("")
txt.focus_set()
return False
else:
print(input)
return False
def oddblue(a,b,c):
svLabel.set(svTxt.get())
frm=Tk()
frm.geometry("250x250")
svTxt = StringVar()
svLabel = StringVar()
svLabelOpr = StringVar()
svLabelDisp = StringVar()
svTxt.trace('w',oddblue)
txt=Entry(frm, width=10, textvariable=svTxt)
txt.place(x=20, y=20)
reg=frm.register(callback)
txt.config(validate="key", validatecommand=(reg, '%S'))
lbl=Label(frm,anchor='e',width=15,relief=SUNKEN,textvariable=svLabel)
lbl.place(x=50,y=50)
lblOpr=Label(frm,width=3,relief=SUNKEN,textvariable=svLabelOpr)
lblOpr.place(x=180,y=50)
lblDisp=Label(frm,anchor='e', width=15,relief=SUNKEN,textvariable=svLabelDisp)
lblDisp.place(x=50,y=70)
txt.focus_set()
frm.mainloop()