PyQt Variables

gregarican greg.kujawa at
Thu Jan 5 12:57:21 EST 2006

I have an application I'm writing using PyQt. I'm trying to create the
various windows by subclassing Qt objects. I have a subclassed
QMainWindow as the parent, and then a series of subclassed QWidgets as
other child windows that get used. How can I pass variables back and
forth between the parent and child windows? For example, if I have a
child window that processes a customer lookup I want the retrieved
values to be passed back to the QMainWindow. I have tried using global
variables, but these variables seem to be global only in the sense of
each subclassed object. Not between the subclassed objects.

Here's a generic sample:
my_value = 'main'
from child_window import *

class Parent_Window(QMainWindow):
        def __init__(self):
                QMainWindow.__init__(self,None,'application main
                print my_value
                child_window= Child_Window()
class Child_Window(QWidget):
        def __init__(self):
                print my_value

This doesn' t seem to work, as the Child_Window class doesn't recognize
the my_value global variable that appears in the Parent_Window class.

More information about the Python-list mailing list