

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 Questions & Answers
- How to enable and disable submit button using jQuery?
- How to disable/ enable checkbox with jQuery?
- Disable a Bootstrap Button
- How to disable a Combobox in Tkinter?
- Disable a button with Bootstrap
- How to enable/disable data connection in iOS programmatically?
- How to enable/disable the GPS programmatically in Android?
- Enable and disable interrupts in Arduino
- How to enable back button in android webview?
- How to enable back button in action bar?
- How to gray out (disable) a Tkinter Frame?
- How to disable/enable an input box with jQuery?
- How to disable (grey out) a checkbutton in Tkinter?
- How to create a Tkinter toggle button?
- How to disable close button on a JFrame in Java?
Advertisements