Mar-27-2021, 05:11 AM
(This post was last modified: Mar-27-2021, 05:11 AM by deanhystad.)
Your question is boring, so I am going to answer a different question.
Views that need to update to reflect changes in data should have an update method. This update method is bound to a notify event associated with the data. When the data changes it sends notification to all the interested parties. Something like this:
Back to your question. Where code exists should have no affect on if arguments can be passed. If you get something from a database in one file, there is no reason why that information cannot be passed as an argument to a function in a different file that displays the information. I think any limitations you see are not real. You think there is something special about code being in different files. The only thing affected by that are module variables, and you should not be using many of those.
Views that need to update to reflect changes in data should have an update method. This update method is bound to a notify event associated with the data. When the data changes it sends notification to all the interested parties. Something like this:
import tkinter as tk class CallbackList(list): """A list of functions to call""" def __call__(self, value): for func in self: func(value) def connect(self, func): """Add function to the list""" self.append(func) class MyData(): """This is my data""" def __init__(self): self.value = 1 self.value_changed = CallbackList() def set_value(self, value): """Set my data and notify that value changed""" self.value = value self.value_changed(self.value) def enter_value(event): """Gets called when Retrun key is pressed in entry widget""" data.set_value(float(event.widget.get())) def update_square(value): """Call this when value changes""" square['text'] = str(value**2) def update_cube(value): """Call this when value changes""" cube['text'] = str(value**3) data = MyData() root = tk.Tk() entry = tk.Entry(root, width=4) entry.pack() entry.bind('<Return>', enter_value) square = tk.Label(root, width=4) square.pack() data.value_changed.connect(update_square) cube = tk.Label(root, width=4) cube.pack() data.value_changed.connect(update_cube) root.mainloop()You want to avoid having one control being directly responsible for changing another control. Try to make each GUI element responsible for doing only one thing, and have that control and associated control do it's job while being as ignorant as possible about other parts of the GUI.
Back to your question. Where code exists should have no affect on if arguments can be passed. If you get something from a database in one file, there is no reason why that information cannot be passed as an argument to a function in a different file that displays the information. I think any limitations you see are not real. You think there is something special about code being in different files. The only thing affected by that are module variables, and you should not be using many of those.