Unwanted Window Popping Up

I am developing some software for a friend’s business using a top-down menu approach. I’ve got the top menu coded and functional in that the slots print a message. Now I am trying to add a 2nd window to get relevant data before I initiate the next part of the process… I am using Add Customer as my experiment. When that option is selected from the menu, I get the window to open that I want, but I get what appears to be a phantom window behind it and I can’t figure out why. Any help would be greatly appreciated.

Both windows were created using QT Designer.
Here’s the code for the program.

import os
import sys
from PySide6.QtUiTools import (QUiLoader)
from PySide6.QtWidgets import (
    QApplication,
    QMainWindow,
    QMenu,
    QWidget
        )

loader = QUiLoader()
basedir = os.path.dirname(__file__)

class Input_Cust_Code(QWidget):
    def __init__(icc):
        super().__init__()
        icc.cci = loader.load(
            os.path.join(basedir,"cust_input.ui"), None
            )
        icc.cci.show()

class menu(QMainWindow):
    def __init__(self):
        super().__init__()
        self.main_menu = loader.load(
            os.path.join(basedir,"main_menu.ui"), None
        )
        self.main_menu.show()

        # Create customer menu
        menu_cust = QMenu(self)
        # Create addAction instances for the customer menu
        add_cust = menu_cust.addAction("Add Customer")
        change_cust = menu_cust.addAction("Change Customer")
        locate_cust = menu_cust.addAction("Locate Customer")

        # Create part menu
        menu_part = QMenu(self)
        # Create addAction instances for the parts menu
        add_part = menu_part.addAction("Add Part")
        change_part = menu_part.addAction("Change Part")
        locate_part = menu_part.addAction("Locate Part")

        # Create model menu
        menu_modl = QMenu(self)
        # Create addAction instances for the model menu
        add_modl = menu_modl.addAction("Add Model")
        change_modl = menu_modl.addAction("Change Model")
        locate_modl = menu_modl.addAction("Locate Model")

        # Create order menu
        menu_ordr = QMenu(self)
        # Create addAction instances for the order menu
        add_ordr = menu_ordr.addAction("Add Order")
        change_ordr = menu_ordr.addAction("Change Order")
        locate_ordr = menu_ordr.addAction("Locate Order")

        # Attach menu options to QtoolButton Menus in .ui file
        self.main_menu.cust_op.setMenu(menu_cust)
        self.main_menu.part_op.setMenu(menu_part)
        self.main_menu.modl_op.setMenu(menu_modl)
        self.main_menu.ordr_op.setMenu(menu_ordr)

        # Connect the QActions to functions
        add_cust.triggered.connect(self.cust_add)
        change_cust.triggered.connect(self.cust_chg)
        locate_cust.triggered.connect(self.cust_loc)

        add_part.triggered.connect(self.part_add)
        change_part.triggered.connect(self.part_chg)
        locate_part.triggered.connect(self.part_loc)

        add_modl.triggered.connect(self.modl_add)
        change_modl.triggered.connect(self.modl_chg)
        locate_modl.triggered.connect(self.modl_loc)

        add_ordr.triggered.connect(self.ordr_add)
        change_ordr.triggered.connect(self.ordr_chg)
        locate_ordr.triggered.connect(self.ordr_loc)
        self.main_menu.show()

    def cust_add(icc):
        print('Add Customer Triggered')
        icc.cust_imp = Input_Cust_Code()
        icc.cust_imp.show()

    def cust_chg(self):
        print('Change Customer Trigger')
    def cust_loc(self):
        print('Locate Customer Triggered')
    def part_add(self):
        print('Add Part Triggered')
    def part_chg(self):
        print('Change Part Trigger')
    def part_loc(self):
        print('Locate Part Triggered')
    def modl_add(self):
        print('Add Model Triggered')
    def modl_chg(self):
        print('Change Model Trigger')
    def modl_loc(self):
        print('Locate Model Triggered')
    def ordr_add(self):
        print('Add Order Triggered')
    def ordr_chg(self):
        print('Change Order Trigger')
    def ordr_loc(self):
        print('Locate Order Triggered')

app = QApplication(sys.argv)
ex = menu()
app.exec()

Thanks again for your assistance!! Much appreciated!!

Hi @WaltMayhew welcome to the forum

The issue is that you’re calling show() twice, once on the UI object itself, and the second time on the QWidget you’re constructing that inside of.

Here

and also here

The class Input_Cust_Code is not actually doing anything in this case. It’s just a simple QWidget (an empty widget, so an empty window).

I think you’re mixing up two different things here. If you look at the PySide6 tutorial here what I think you want is.

That is, just load the class from the UI file and show that directly.

Saying that, I would usually recommend that you convert the UI files into Python so you can import them and use them like any other widget. See the bottom of the tutorial linked above for an example of doing that.

Thank you for your review and suggestion(s). I fixed this particular issue, but appreciate your feedback. I’ll take a look at your suggestions.

Right now I’m using the loader so I can prototype the changes to the windows developed in QT Design. I saw in your book the various options and decided to use that method in development so I could easily prototype windows development. I’ll reevaluate that approach when I get the project finished.

I would be interested in a further discussion about your assistance. I didn’t see a way to contact you directly so I emailed to the address provided for feedback on one of your books. They have been very helpful.