目前我有一个禁用按钮的场景。现在我想在用户在tkinter条目小部件中输入一些输入时启用按钮。
请建议。
谢谢!
答案 0 :(得分:2)
答案 1 :(得分:0)
你可以按照这个question和@Furas说你可以将函数绑定到Entry,就像这样
from Tkinter import Tk, Entry
root = Tk()
frame = Frame(root) #"frame" represents the parent window, where the entry widget should be placed.
frame.pack()
#GUI widgets
entry = Entry(frame, width=80) #The syntax of an entry widget
entry.pack(side='right')
#callbacks
def enableEntry():
entry.configure(state="normal")
entry.update()
def disableEntry():
entry.configure(state="disabled")
entry.update()
def click(key):
#print the key that was pressed
print key.char
var = StringVar()
disableEnButton = Radiobutton(frame, text="Disable", variable=var, value="0", command=disableEntry)
disableEnButton.pack(anchor=W)
enableEnButton = Radiobutton(frame, text="Enable", variable=var, value="1", command=enableEntry)
enableEnButton.pack(anchor=W)
#Bind entry to any keypress
entry.bind("<Key>", click)
root.mainloop() #This is necessary for the event loop to service events such as button clicks