Skip to content
Advertisement

Open Window when Clicked on Push Button in Main Window PyQt5 Python

I have gone through the various post similar post which are having similar problems, tried out the answers also but it didn’t worked for me. So here is my problem –

I have two windows – TestBox and MailBox, when i click on the TestBox Pushbutton along with Input Path argument, it has to open the MailBox Window, This new window MailBox will send the ModifiedPath to the TestBox again when i closes the MailBox window

  1. I have created both windows in PyQt5 Tool and created ui file and then converted to the Python file using – python -m PyQt5.uic.pyuic testboxui.ui -o testboxui.py

  2. I am not touching testboxui.py or mailboxui.py file as they keep on changing any modifications done by reconverting. Instead i have created another file TestBox.py and MailBox.py to import and write functions.

Here is the producible minimal code –

TestBox.py [Main Application Code]

JavaScript

testboxui.py [Generated by PyQt5 Tool directly from UI file]

JavaScript

MailBox.py [Child Application Code]

JavaScript

maillistui.py – [Produced by PyQt5 directly from ui file]

JavaScript

Previously i used to make the PyQt5 dialog with QtWidgets.QDialog which i am able to load easily in QtWidgets.QApplication. But here both are QApplication (QMainWindow) but makes to difficult to call ui within UI.

Is there any thing wrong i am doing here ???

Advertisement

Answer

Only one QApplication should be created, in your case for each script you create 2 unnecessarily, eliminate the following codes:

JavaScript

Correcting the above, another error occurs but for this Python points out the error messages, in the case of many IDEs they do not handle Qt errors, so I recommend you run it in the console and you will get the following error message:

JavaScript

Which clearly indicates that the AppWindow_MailList class accepts a single parameter(RcvPath) but you pass it 2. I do not know if it is a typo or if you do not know the use of “self” in python (if it is the latter then it is recommended to read What is the purpose of the word ‘self’?)

JavaScript

Even solving that error there is another problem, AppWindow_MailList is a QMainWindow so it does not have any exec_() method, it seems that you have tried to use the code of some post that uses QDialog without understanding the logic of the solution.

In general, each widget has a purpose:

  • A QWidget is a generic widget that can be used as a base to build any other type of widget or container, similar to the divs in html.

  • A QDialog is a widget whose purpose is to request information from the user, so the exec_ () method returns the status of the request (if it was accepted or rejected) blocking the eventloop.

  • A QMainWindow has the purpose of offering a main window since it contains a toolbars, statusbar, menubar, dockwidets, etc.

So to implement your objective you have to choose the right elements, considering that I will restructure your application.

mailbox.ui

JavaScript

testbox.ui

JavaScript
JavaScript

mailbox.py

JavaScript

testbox.py

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement