shihas backer
shihas backer

Reputation: 41

How to disable keyboard inputs when using Entry on Tkinter on python?

How can I disable keyboard input entries when using Entry on Tkinter in python I was coding for a calculator project in python. So I need to make a screen like text box using Entry.
I couldn't remove keyboard inputs from the Entry field.

Upvotes: 2

Views: 2112

Answers (2)

shihas backer
shihas backer

Reputation: 41

you can disable keyboard characters from an Entry field in Tkinter using:

from tkinter import *
root=Tk()

txtDisplay = Entry(root, width=28, justify=RIGHT)    
txtDisplay.grid(row=0, column=0, columnspan=5, pady=1)
txtDisplay.bind("<Key>", lambda e: "break")          # Disable characters from keyboard

root.mainloop()

Upvotes: 2

Ajay Lingayat
Ajay Lingayat

Reputation: 1673

You can set the state of Entry widget to DISABLED.

Example:-

win = tk.Tk()
ent = Entry(win, state=DISABLED)
ent.pack() 

Upvotes: 3

Related Questions