如何将 Tkinter 按钮状态从禁用更改为正常?
Tkinter 提供 Button 小部件以创建触发事件的按钮。假设我们创建了一个已经在应用程序中禁用的按钮。为了更改按钮的状态,我们可以使用 state 属性。
state 属性用于在应用程序中启用和禁用按钮。为了更改应用程序的状态,我们可以执行两个操作:state=DISABLED 和 state=NORMAL。
示例
#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()输出 1
按钮被禁用时的输出:

输出 2
当 Button state=NORMAL 时的输出:

广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP