Skip to content
Advertisement

Accessing variables from other tab in notebook

Tab1 and Tab2 of the notebook

Hi all, I was unsuccessful with my last question in this group because my code was too long. I have now brought my code to a minimum and added a screenshot. I hope this time everything is clear and not confusing. My question is: how can I check the variable “val” in Tab1 whether it is smaller than 5. If not, the frame and button in Tab1 must be gray and disabled. The button must not do anything. The problem is that I have defined “val” as global, but it still brings the error message that “val” is unknown. Any idea why “val” is not known in Tab1?

JavaScript

Advertisement

Answer

I think you should use the object-oriented way to build your GUI. From what I understood of your situation, here’s my suggested solution:

Tab1.py

JavaScript

Tab2.py

JavaScript

TabTop.py

JavaScript

To synchronize the information between the two tabs, you need a tkinter variable instance that you connect between the ttk.Entry and a callback function that will be triggered when the content of the ttk.Entry‘s is changed.

I know there’s not a lot of documentation on tkinter. I would recommend :


We could go even more object-oriented:

TabTop2.py

JavaScript

Is that what your tried to do?

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement