Python Forum
[PyQt] Managing variables accross a multiple module GUI
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] Managing variables accross a multiple module GUI
#1
I would like to know what are the best practices to manage variables in a complex application (ie multiple windows/menus/forms etc). I am relatively new to GUI programming so I apologize for any misconception I would have.
My issue is with variables representing data or application-wide settings that are meant to me shared between the different modules

Up to now I have found 2 approaches:
1) the variables are assigned in a common top level scope (mainwindow for ex) and variable values are passed to child widgets when needed.
This seems to be the safest approach as only the relevant variables are passed as argument to the child scope. However the values modified in the child scope must eventually be returned to update the "original" variable in the top level scope. This method looks cumbersome when a large number of variables is involved over multiple scope levels.
-or-
2) the variables are assigned in a separate .py file which is imported into each relevant module. This method is more direct, no passing arguments, no need to return anything since the variables can be directly read/modified from any scope inside the module. I personnaly do not like this approach which looks like an equivalent of global variables since the data can be accessed from anywhere inside the module without explicitly passing arguments.

As I see it, both methods have their drawbacks and i am unsure what whould constitute a "good" approach for a GUI developper. Any thoughts or recommendations?
Reply


Messages In This Thread
Managing variables accross a multiple module GUI - by Oolongtea - Jun-27-2019, 10:47 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question [Tkinter] Defining a self made module's function to interact with the main .py variables? Gilush 9 4,419 Jun-08-2020, 09:08 AM
Last Post: Gilush

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020