Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7909689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T12:32:58+00:00 2026-06-03T12:32:58+00:00

from PyQt4.QtGui import QApplication, QMainWindow, QPushButton, \ QLabel, QVBoxLayout, QWidget from PyQt4 import QtGui

  • 0
from PyQt4.QtGui import QApplication, QMainWindow, QPushButton, \
        QLabel, QVBoxLayout, QWidget
from PyQt4 import QtGui
import sys

import subprocess

class MainWindow1(QMainWindow):
    def __init__(self, parent=None):
        QMainWindow.__init__(self, parent) 
        button = QPushButton('NotePad')

        label = QLabel('MainWindow1')

        centralWidget = QWidget()
        vbox = QVBoxLayout(centralWidget)
        vbox.addWidget(label)
        vbox.addWidget(button)
        self.setCentralWidget(centralWidget)

        button.clicked.connect(self.LaunchNotepad)

    # Some code here - including import subprocess
    def LaunchNotepad(self):

        returncode = subprocess.call(['python', 'notepad.py'])




if __name__ == '__main__':
    app = QApplication(sys.argv)
    mainwindow1 = MainWindow1()
    mainwindow1.show()
    sys.exit(app.exec_())

that code creates a main window with a button, when i press the button i would like it to import my file called “notepad”, (I think it does) however it opens it and closes it straight away. I need to be able to use the program notepad until i close it in which case it should revert back to the original window. Eventually i will have 3 or 4 buttons importing 3 or 4 different programs

I dont think there is an error in notepad because when i only have the statement “import notepad” it runs perfectly

note: the notepad file is just a simple text program (much like the “notepad” program on windows pcs)

thanks in advance

edit here is note pad code:

import sys
import os
import datetime as dt
from PyQt4 import QtGui
from PyQt4 import *


class Notepad(QtGui.QMainWindow):
    def __init__(self):
        super(Notepad, self).__init__()
        self.initUI()






    def initUI(self):
        newAction = QtGui.QAction('New', self)
        newAction.setShortcut('Ctrl+N')
        newAction.setStatusTip('Create new file')
        newAction.triggered.connect(self.newFile)  
        saveAction = QtGui.QAction('Save', self)
        saveAction.setShortcut('Ctrl+S')
        saveAction.setStatusTip('Save current file')
        saveAction.triggered.connect(self.saveFile)
        openAction = QtGui.QAction('Open', self)
        openAction.setShortcut('Ctrl+O')
        openAction.setStatusTip('Open a file')
        openAction.triggered.connect(self.openFile)

        closeAction = QtGui.QAction('Close', self)
        closeAction.setShortcut('Ctrl+Q')
        closeAction.setStatusTip('Close Notepad')
        closeAction.triggered.connect(self.close)
        menubar = self.menuBar()

        fileMenu = menubar.addMenu('&File')
        fileMenu.addAction(newAction)
        fileMenu.addAction(saveAction)
        fileMenu.addAction(openAction)
        fileMenu.addAction(closeAction)

        #help menu
        helpMenu = menubar.addMenu('&Help')
        aboutAction = QtGui.QAction('About', self)
        aboutAction.setShortcut('Ctrl+A')
        aboutAction.setStatusTip('About')
        helpMenu.addAction(aboutAction)
        aboutAction.triggered.connect(self.about) 

        self.text = QtGui.QTextEdit(self)

        self.setCentralWidget(self.text)
        self.setGeometry(300,300,300,300)
        self.setWindowTitle('Notepad')


        self.show()
        self.statusBar()










    def newFile(self):
        self.text.clear()

    def saveFile(self):
        filename = QtGui.QFileDialog.getSaveFileName(self, 'Save File', os.getenv('HOME'))
        f = open(filename, 'w')
        filedata = self.text.toPlainText()
        f.write(filedata)
        f.close()

    def openFile(self):
        filename = QtGui.QFileDialog.getOpenFileName(self, 'Open File', os.getenv('HOME'))
        f = open(filename, 'r')
        filedata = f.read()
        self.text.setText(filedata)
        f.close()

        self.setGeometry(300,300,300,300)
        self.setWindowTitle('Notepad')
    self.show()
    def closeEvent(self, event):


        reply = QtGui.QMessageBox.question(self, 'Message',
            "Are you sure to quit?", QtGui.QMessageBox.Yes | 
            QtGui.QMessageBox.No, QtGui.QMessageBox.No)

        if reply == QtGui.QMessageBox.Yes:
            event.accept()
        else:
            event.ignore()
    def about(self, event):
        reply = QtGui.QMessageBox.question(self, 'About Task Manager',
            "This is a notepad todo list program written by craig murch")


        return Notepad



if __name__ == '__main__':
    app = QtGui.QApplication(sys.argv)
    notepad = Notepad()

    sys.exit(app.exec_())

EDIT: The edited code above now does want i want it to do however it loads the cmd as well which i dont want to, how do i stop it loading the cmd?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T12:33:00+00:00Added an answer on June 3, 2026 at 12:33 pm

    Well, in your Notepad code you have

    sys.exit(app.exec_())
    

    This will close the entire process. So if you’re importing it from your parent window then yeah, it should be closing your application.

    Also, regardless of which GUI framework you use it’s always a bad idea to mix mainloops in the same process. Instead, you should use subprocess to call your other application:

    # Some code here - including import subprocess
    import os
    def LaunchNotepad(self):
        self.DoSomething() #Or whatever you want to do before your program launches
        returncode = subprocess.call(['pythonw', 'notepad.py'],
                                     stdout=open(os.devnull, 'w'),
                                     stderr=open(os.devnull, 'w'))
        self.ShowMe() #Won't run until notepad finishes
        if not returncode:
            self.ShowError("Notepad exited abnormally!")
    

    That’s a pretty basic example of what you could do.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this sample of code: import sys from PyQt4.QtGui import (QApplication, QHBoxLayout, QVBoxLayout,
Consider the code below: #!/usr/bin/env python from PyQt4 import QtCore, QtGui import os,sys class
In this sample of code: from PyQt4.QtGui import QDialog, QPushButton, QRadioButton, QHBoxLayout, QApplication, QButtonGroup
I have the following code: #!/usr/bin/env python import sys from PyQt4 import QtGui, QtCore
import sys from PyQt4.QtGui import * from PyQt4.QtCore import * from PyQt4.QtWebKit import QWebView
I have this sample of code: import sys import time from PyQt4.QtGui import *
web_view_crash.py import sys from PyQt4.QtGui import * from PyQt4.QtCore import * from PyQt4.QtWebKit import
How can i make my qmenu checkable? from PyQt4 import QtGui app = QtGui.QApplication([])
Simple code demonstrating the problem: #!/usr/bin/env python import sys from PyQt4.QtCore import QObject, SIGNAL
The PyQt4 QTableWidget has both cellPressed and cellClicked signals. From the name, and the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.