0

I have a question on the trace method for multiple variables. I want to disable a button "run" when StringVar is an empty value. I used the trace method but this will only trace separately each variable but does not consider combo of two. For example, one scenario, I change two values to empty strings in the entry widget and than I change one of them to a number,the other one is still an empty string, as the result the button will be enabled. How will I keep the button disabled in this scenario?

self.var_5_x.trace("w", self.on_entry_trace_x)
self.var_3_y.trace("w", self.on_entry_trace_y)

def on_entry_trace_x(self, *args):

    new_state = "disabled" if self.var_5_x.get() == "" else "normal"
    self.button_1.configure(state=new_state)

def on_entry_trace_y(self, *args):

    new_state = "disabled" if self.var_3_y.get() == "" else "normal"
    self.button_1.configure(state=new_state)
karlos
  • 3
  • 1
  • 2
  • Does this answer your question? [What are the arguments to Tkinter variable trace method callbacks?](https://stackoverflow.com/questions/29690463/what-are-the-arguments-to-tkinter-variable-trace-method-callbacks) – stovfl Mar 30 '20 at 19:11
  • You should probably have a single function for both traces - that checks both vars, and sets the button state accordingly. – jasonharper Mar 30 '20 at 19:16
  • I was thinking about one function but I have six variables so I hoped there is more neat solution for this. – karlos Mar 30 '20 at 19:29
  • stovfl, I am not sure how the referenced topic is similar to my query? – karlos Mar 30 '20 at 19:33
  • @karlos ***"similar to my query?"*** It explains how to use **one** callback for multiple variable. – stovfl Mar 30 '20 at 19:34
  • @stovfl, sorry I am just a beginner so hoped for some more help. I read the tread and struggling to understand how I can define one call back to ensure that all combos can disable the button. Is this related to a first argument "name"? – karlos Mar 30 '20 at 19:56
  • ***"related to a first argument "name"***: Yes that's the proposed way to go. But according to your example code you don't use any `*arg`, you simple have to bind to **one** callback and build condition that fit your needs. – stovfl Mar 30 '20 at 20:09

0 Answers0