Tkinter: Tracing the state of a widget

692 Views Asked by At

I am aware that it is possible to trace the changes of, say, the entered value in an Entry widget by using e.g. a StringVar and a variable observer like Trace. Is it possible to also trace the state of a widget? Let's say we have the code:

from tkinter import *

class My_Window:

    def __init__(self, root):

        self.button1 = Button(root, text="Enter", command = self.disable_entrybox)
        self.get_info_box1 = Entry(root)
        self.button2 = Button(root, text="Enter", command = self.disable_entrybox) 
        self.get_info_box2 = Entry(root)
        self.button1.pack()
        self.get_info_box1.pack()
        self.button2.pack()
        self.get_info_box2.pack()
        self.get_info_box2.config(state="disable")

    def disable_entrybox(self):
        x = self.get_info_box1.get()
        self.get_info_box1.config(state="disable")


root = Tk()
my_window = My_Window(root)
root.mainloop()

And I want to trace if get_info_box1is disabled or not, and if it's disabled, change the state of get_info_box2 to "normal". Is there any way to do this?

0

There are 0 best solutions below