PyQT Design Organization

I want to organize a PyQT project, I tried to put the user interfaces in a subfolder and import them as follows:

import sys
sys.path.append('UI/gui_sensors')
from gui_sensors_extended import Ui_SensorsWindow_Extended

But it gives me an error because it cannot find * Ui_SensorsWindow * , a ui class that was inherited in * Ui_SensorsWindow_Extended *

So what do you propose to organize my project? And how can I handle it in code?

+3
source share
2 answers

When structuring a python project, there is one key thing to keep in mind: the directory of the currently running script is automatically added to the beginning sys.path.

, main.py script , , , script. , :

project /
    main.py
    package /
        __init__.py
        app.py
        ui /
            __init__.py
            mainwindow.py

main.py script - :

if __name__ == '__main__':

    import sys
    from package import app
    sys.exit(app.run())

app gui :

from package.ui.mainwindow import Ui_MainWindow

. , , :

project /
    main.py
    package /
    ...
        dialogs /
            __init__.py
            search.py

search gui :

from package.ui.search import Ui_SearchDialog

python , sys.path, .

+9

, :

import sys
import os.path as osp
path = osp.dirname(__file__)
sys.path.append(osp.join(path, 'UI/gui_sensors'))
from gui_sensors_extended import Ui_SensorsWindow_Extended

__file__

0

All Articles