Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Tkinter, How I disable Entry?

How I disable Entry in Tkinter.

def com():
       ....

entryy=Entry()
entryy.pack()

button=Button(text="Enter!", command=com, font=(24))
button.pack(expand="yes", anchor="center")

As I said How I disable Entry in com function?

like image 723
Emek Kırarslan Avatar asked Nov 09 '13 14:11

Emek Kırarslan


People also ask

How do you disable a frame?

To disable all the widgets inside that particular frame, we have to select all the children widgets that are lying inside that frame using winfor_children() and change the state using state=('disabled' or 'enable') attribute.

How do you disable the Close button in Tkinter?

Disable Exit (or [ X ]) in Tkinter Window To disable the Exit or [X] control icon, we have to define the protocol() method. We can limit the control icon definition by specifying an empty function for disabling the state of the control icon.

How does entry work Tkinter?

An Entry widget in Tkinter is nothing but an input widget that accepts single-line user input in a text field. To return the data entered in an Entry widget, we have to use the get() method. It returns the data of the entry widget which further can be printed on the console.


2 Answers

Set state to 'disabled'.

For example:

from tkinter import *

root = Tk()
entry = Entry(root, state='disabled')
entry.pack()
root.mainloop()

or

from tkinter import *

root = Tk()
entry = Entry(root)
entry.config(state='disabled') # OR entry['state'] = 'disabled'
entry.pack()
root.mainloop()

See Tkinter.Entry.config


So the com function should read as:

def com():
    entry.config(state='disabled')
like image 68
falsetru Avatar answered Oct 12 '22 17:10

falsetru


if we want to change again and again data in entry box we will have to first convert into Normal state after changing data we will convert in to disable state

import tkinter as tk
count = 0

def func(en):
    en.configure(state=tk.NORMAL)
    global count
    count += 1
    count=str(count)
    en.delete(0, tk.END)
    text = str(count)
    en.insert(0, text)
    en.configure(state=tk.DISABLED)
    count=int(count)


root = tk.Tk()

e = tk.Entry(root)
e.pack()

b = tk.Button(root, text='Click', command=lambda: func(e))
b.pack()

root.mainloop()
like image 37
Osama Shakeel Avatar answered Oct 12 '22 19:10

Osama Shakeel