Python Forum
Running external Python file as a subwindow
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Running external Python file as a subwindow
#11
Thanks for your feedback, Axel. But what I need is the external file second_win to open inside the mdiArea of win...
Reply
#12
The principle is the same.

win.py

from PyQt5.QtWidgets import QMainWindow, QApplication, QAction, QMdiArea
from PyQt5.QtGui import QIcon
import second_win

class MainWin(QMainWindow):
    def __init__(self, parent = None):
        super(MainWin, self).__init__(parent)
        self.setupUI()
        
    def setupUI(self):
        self.setGeometry(0, 0, 600, 400)
        self.mdi_area = QMdiArea()
        self.file_tool_bar = self.addToolBar("File")
        self.my_action = QAction(QIcon.fromTheme("folder"), "", triggered = self.show_second_win)
        self.file_tool_bar.addAction(self.my_action)
        self.setCentralWidget(self.mdi_area)
        
    def show_second_win(self):
        print("open second win")
        self.sw = second_win.SecondWin()
        self.sw.setFixedSize(400, 300)
        self.mdi_area.addSubWindow(self.sw)
        self.sw.show()


if __name__ == '__main__':
    import sys
    app = QApplication(sys.argv)
    win = MainWin()
    win.setWindowTitle("Main Window")
    win.show()

    sys.exit(app.exec_())
Reply
#13
Of course. Thanks.
Reply
#14
You really don't need to quote the previous post in its entirety; it just wastes space.

Your code is already difficult to maintain (and test!): use of global variables, no separation of concerns (database code is mixed in with UI code, for example).
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyQt] Subwindow catlessness 5 2,858 Oct-23-2021, 06:28 PM
Last Post: catlessness
  [PyQt] Can't neither setWindowFlags nor setFixedSize of a subwindow. JayCee 10 4,150 Aug-06-2021, 08:06 PM
Last Post: JayCee
  [PyQt] App crashes when reopening a subwindow JayCee 13 5,096 Aug-04-2021, 01:51 AM
Last Post: JayCee

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020