Python tkinter deaktivieren Sie die Taste, bis alle Felder ausgefüllt sind

Sagen wir, ich habe 2 Eintrag widgets, 1 option-Menü(Dropdown-Liste) und 1 Taste in tkinter. Wie kann ich die button-widget Status auf DEAKTIVIERT, bis alle 3 widgets gefüllt werden, indem der Benutzer?Dies ist, was ich derzeit habe:

import Tkinter as tk

root = tk.Tk()

entry1=tk.Entry(root,width=15).grid(row=1,column=1)
entry2=tk.Entry(root,width=15).grid(row=1,column=2)

choices=('a','b','c')
var=tk.StringVar(root)
option=tk.OptionMenu(root,var,*choices)
option.grid(row=1,column=3)

button=tk.Button(root,text="submit")
button.grid(row=1,column=4)

root.mainloop()

--EDIT--

Versucht auf diese Weise, aber ich glaube nicht, dass dies der richtige Weg, es zu tun.

import Tkinter as tk

root = tk.Tk()
def myfunction(event):
    x=var.get()
    y=entry1.get()
    z=entry2.get()
    print len(x),":",len(y),":",len(z)
    if len(y)>0 and len(x)>0 and len(z)>0:
        button.config(state='normal')
    else:
        button.config(state='disabled')
entry1=tk.Entry(root,width=15)
entry1.grid(row=1,column=1)
entry2=tk.Entry(root,width=15)
entry2.grid(row=1,column=2)

choices=('a','b','c')
var=tk.StringVar(root)
option=tk.OptionMenu(root,var,*choices)
option.grid(row=1,column=3)

button=tk.Button(root,text="submit")
button.grid(row=1,column=4)

root.bind("<Enter>", myfunction)
root.mainloop()

InformationsquelleAutor Chris Aung | 2013-05-22

Schreibe einen Kommentar