I am making a calculator using tkinter and I wish to do the following:
- Disable keyboard input for the
Entry
widget so that the user can only input through the buttons.- Even after disabling keyboard input for the
Entry
widget, I wish to be able to change the background and foreground of the widget.- I wish to hide the console window because it is totally useless in the use of this calculator.
- I don't want to let the user resize the
root
window. How do I disallow the resizing of theroot
window?
Here is my code so far...
from tkinter import *
root = Tk()
root.title("Calculator")
root.config(background="black")
operator = ""
textVar = StringVar()
def valInput(number):
global operator
operator+=str(number)
textVar.set(operator)
display = Entry(root, textvariable=textVar, font=("Arial", 14, "bold"), bg="lightblue", fg="black", justify="right")
display.grid(row=0, column=0, columnspan=4)
btn7 = Button(root, font=("Arial", 12, "bold"), bg="orange", fg="red", text="7", command= lambda : valInput(7))
btn7.grid(row=1, column=0)
"""
And more buttons...
"""
root.mainloop()
As you can see, I can input into the Entry
widget using buttons but later on, after the calculator is complete, if the user inputs characters like abcd... it will cause problems and show errors. How do I disallow keyboard entry so that I can avoid these errors?
I want to make my calculator a bit colorful. I changed the color of the root
window, the buttons and also the color of the Entry
widget. Is there any way to change the color of the widget even after it is disabled?
I don't need the console window while using this calculator. How do I hide it?
If I resize the root
window, the calculator becomes ugly, besides, resizing the window isn't necessary. So how do I prevent the user from resizing the window?
.py
to.pyw
the command window will no longer appear. – scotty3785