- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to Disable / Enable a Button in TKinter?
There are various attributes and properties in each tkinter widget to help us extend the functionality of the application. Tkinter Button widgets can be enabled and disabled by defining its state in the Button Object. The state attribute generally accepts two values Normal and Disabled which are used for enabling and disabling the button, respectively.
Example
#Import necessary Library from tkinter import * from tkinter import ttk from tkinter.filedialog import asksaveasfile #Create an instance of tkinter window win= Tk() #Set the geometry of tkinter window win.geometry("750x250") #Define the function to change the value in label widget def change_text(label): label.configure(text= "Hey, I am Label-2", background="gray91") #Create a Label label = Label(win, text= "Hey, I am Label-1", font= ('Helvetica 15 underline'), background="gray76") label.pack(pady=20) #Create a button btn= ttk.Button(win,text= "Change", command= lambda:change_text(label), state= DISABLED) btn.pack(pady=10) win.mainloop()
Output
Running the above code will display a window that has a disabled button. We can change the state of the button to Normal.
Now, change the value of the state attribute to NORMAL to make the button active on the window.
- Related Articles
- How to enable and disable submit button using jQuery?
- How to disable a Combobox in Tkinter?
- How to disable/ enable checkbox with jQuery?
- How to enable/disable data connection in iOS programmatically?
- How to enable/disable the GPS programmatically in Android?
- How to enable back button in action bar?
- How to enable back button in android webview?
- Disable a Bootstrap Button
- How to disable (grey out) a checkbutton in Tkinter?
- How to disable close button on a JFrame in Java?
- How to disable/enable an input box with jQuery?
- How to gray out (disable) a Tkinter Frame?
- How to enable back button action in action bar?
- How to update a Button widget in Tkinter?
- How to highlight a tkinter button in macOS?

Advertisements