Hello I'm new to python and I'm programing an application using PyQt at the moment now i would like to know how to pass some variables from my main parent page to included pages which in the own right have a lot of processing, event handling and data entry and retrieval as well.

is this possible with python or do i have to do all my main code on the main page?

i have no problem getting variable from included pages onto the main page i just want to send variables the other way.

is it only a one way system in python not like PHP which can access variables globally regardless of it its a parent page or an included child page.

the reason I'm doing this is the application i want to build is a large ERP/CMR type application which will have many app pages so i cant put every thing on the main page as i want to break it up into modules. but i cant figure out how to get variables from the main page into a another included page which might manage the sales part of the application with all the app pages for the sales team and another module with all the app pages for the accounts team. the main page manages password entry and user management also activity management.
but i cant retrieve details of who's logged in so i can show the appropriate app page of the application with the settings for that user and setup database interaction for that particular user into the included pages


you help on this would be very grateful

Dani AI

Generated

Brief answer up front: yes — pass data to child pages by giving them a reference to the data or a small "session/state" object when you create them, and use signals/slots (or simple callbacks) to notify the main window of changes. That avoids PHP-style hidden globals and keeps modules decoupled and testable. (Building on 's hint about passing parameters and 's request for an example.)

A minimal pattern: create a small Session/state object, pass it into each module's constructor, and emit a signal when something important changes. Example (PyQt-style pseudocode):

from PyQt5.QtCore import pyqtSignal
from PyQt5.QtWidgets import QWidget

class Session(object):
    def __init__(self, user=None):
        self.user = user

class SalesWidget(QWidget):
    userChanged = pyqtSignal(object)

    def __init__(self, session, parent=None):
        super().__init__(parent)
        self.session = session

    def apply_user_update(self, new_user):
        self.session.user = new_user
        self.userChanged.emit(new_user)

# in main app:
session = Session(user={'name':'Alice','id':42})
sales = SalesWidget(session)
sales.userChanged.connect(main_on_user_changed)

Why this works and practical tips: passing the same Session instance means children read the current state by reference. Use signals to notify other parts when you replace the entire object (reassigning breaks references). For long-running processing keep work in a QThread/QRunnable and send results back with signals — never touch widgets from worker threads. If many modules need global-ish access, store a single context on QApplication (e.g., QApplication.session) or pass it explicitly; prefer explicit passing for clarity and testability.

Quick troubleshooting checklist: ensure you're handing the same object (not a copy), connect signals before showing widgets, watch for reassignments that leave other modules with stale references, and move heavy loops off the GUI thread.

Recommended Answers

All 2 Replies

Your choice of words is very unique and I'm not sure that I understand your dilemma; but perhaps you are asking about passing parameters to a function that you've imported from another module?

import os

os.listdir('/mydir/test/python')

Like that.

Include a small code snippet that demonstrates what you want (it doesn't have to work, just use descriptive variable names). I think you are talking about passing variables from/to functions, classes, and separate program files, which is done in practically every program written, but a descriptive piece of code would help to clarify.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.