How to change Tkinter Button state from disabled to normal?


Tkinter provides Button widgets to create a button for triggering an event. Let us suppose we have created a button that is already disabled in an application. In order to change the state of the button, we can use the state property.

The state property is used to enable and disable a button in an application. In order to change the state of the application, we have two operations: state=DISABLED and state=NORMAL.

Example

#Import the required libraries
from tkinter import *

#Create an instance of tkinter frame
win= Tk()

#Set the geometry of frame
win.geometry("650x450")

#Define a function for Button Object
def quit_win():
   win.destroy()

#Create a button to quit the window
Button(win,text="Quit", command=quit_win, font=('Helvetica bold',20),
state= NORMAL).pack(pady=5)

win.mainloop()

Output 1

The output when the button is disabled,

Output 2

Output when Button state=NORMAL

Updated on: 26-Mar-2021

694 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements