[PyQt] enter from py exported by pyqt5 designer to another py file - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: [PyQt] enter from py exported by pyqt5 designer to another py file (/thread-11220.html) |
enter from py exported by pyqt5 designer to another py file - royer14 - Jun-29-2018 Hello, I have difficulty entering a py, which I had exported from pyqt5 designer with the name "program.py", using another py with name "programa.py". Look at the code, please. program.py # -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'untitled.ui' # Created by: PyQt5 UI code generator 5.6 # WARNING! All changes made in this file will be lost! from PyQt5 import QtCore, QtGui, QtWidgets class Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(708, 596) MainWindow.setMinimumSize(QtCore.QSize(120, 120)) self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.mdiArea = QtWidgets.QMdiArea(self.centralwidget) self.mdiArea.setGeometry(QtCore.QRect(0, 0, 731, 551)) palette = QtGui.QPalette() brush = QtGui.QBrush(QtGui.QColor(240, 240, 240)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Window, brush) brush = QtGui.QBrush(QtGui.QColor(85, 255, 127)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Highlight, brush) brush = QtGui.QBrush(QtGui.QColor(240, 240, 240)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Window, brush) brush = QtGui.QBrush(QtGui.QColor(240, 240, 240)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Highlight, brush) brush = QtGui.QBrush(QtGui.QColor(170, 170, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Window, brush) brush = QtGui.QBrush(QtGui.QColor(51, 153, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Highlight, brush) self.mdiArea.setPalette(palette) self.mdiArea.setSizeAdjustPolicy(QtWidgets.QAbstractScrollArea.AdjustIgnored) brush = QtGui.QBrush(QtGui.QColor(34, 36, 62)) brush.setStyle(QtCore.Qt.SolidPattern) self.mdiArea.setBackground(brush) self.mdiArea.setViewMode(QtWidgets.QMdiArea.SubWindowView) self.mdiArea.setDocumentMode(False) self.mdiArea.setTabsMovable(False) self.mdiArea.setTabPosition(QtWidgets.QTabWidget.North) self.mdiArea.setObjectName("mdiArea") self.Youtube = QtWidgets.QWidget() self.Youtube.setObjectName("Youtube") MainWindow.setCentralWidget(self.centralwidget) self.menubar = QtWidgets.QMenuBar(MainWindow) self.menubar.setGeometry(QtCore.QRect(0, 0, 708, 21)) self.menubar.setObjectName("menubar") self.menuInicio = QtWidgets.QMenu(self.menubar) self.menuInicio.setObjectName("menuInicio") self.menuImportar = QtWidgets.QMenu(self.menuInicio) font = QtGui.QFont() font.setPointSize(12) font.setBold(False) font.setWeight(50) self.menuImportar.setFont(font) icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap(":/document-import-2.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.menuImportar.setIcon(icon) self.menuImportar.setToolTipsVisible(False) self.menuImportar.setObjectName("menuImportar") self.menuAyuda = QtWidgets.QMenu(self.menubar) self.menuAyuda.setObjectName("menuAyuda") MainWindow.setMenuBar(self.menubar) self.statusbar = QtWidgets.QStatusBar(MainWindow) self.statusbar.setObjectName("statusbar") MainWindow.setStatusBar(self.statusbar) self.toolBar_2 = QtWidgets.QToolBar(MainWindow) self.toolBar_2.setObjectName("toolBar_2") MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.toolBar_2) self.toolBar = QtWidgets.QToolBar(MainWindow) self.toolBar.setObjectName("toolBar") MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.toolBar) self.actionAbrir = QtWidgets.QAction(MainWindow) icon1 = QtGui.QIcon() icon1.addPixmap(QtGui.QPixmap(":/new.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.actionAbrir.setIcon(icon1) font = QtGui.QFont() font.setPointSize(12) self.actionAbrir.setFont(font) self.actionAbrir.setObjectName("actionAbrir") self.actionDocumento = QtWidgets.QAction(MainWindow) self.actionDocumento.setEnabled(False) icon2 = QtGui.QIcon() icon2.addPixmap(QtGui.QPixmap(":/document-preview.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.actionDocumento.setIcon(icon2) font = QtGui.QFont() font.setPointSize(12) self.actionDocumento.setFont(font) self.actionDocumento.setObjectName("actionDocumento") self.actionSalir = QtWidgets.QAction(MainWindow) icon3 = QtGui.QIcon() icon3.addPixmap(QtGui.QPixmap(":/application-exit.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.actionSalir.setIcon(icon3) font = QtGui.QFont() font.setPointSize(12) self.actionSalir.setFont(font) self.actionSalir.setObjectName("actionSalir") self.actionAyuda = QtWidgets.QAction(MainWindow) icon4 = QtGui.QIcon() icon4.addPixmap(QtGui.QPixmap(":/system-help.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.actionAyuda.setIcon(icon4) self.actionAyuda.setObjectName("actionAyuda") self.actionAcerca = QtWidgets.QAction(MainWindow) self.actionAcerca.setObjectName("actionAcerca") self.actionImprimir = QtWidgets.QAction(MainWindow) icon5 = QtGui.QIcon() icon5.addPixmap(QtGui.QPixmap(":/printer.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.actionImprimir.setIcon(icon5) self.actionImprimir.setObjectName("actionImprimir") self.menuImportar.addAction(self.actionDocumento) self.menuInicio.addAction(self.actionAbrir) self.menuInicio.addAction(self.menuImportar.menuAction()) self.menuInicio.addSeparator() self.menuInicio.addAction(self.actionImprimir) self.menuInicio.addAction(self.actionSalir) self.menuAyuda.addAction(self.actionAyuda) self.menuAyuda.addAction(self.actionAcerca) self.menubar.addAction(self.menuInicio.menuAction()) self.menubar.addAction(self.menuAyuda.menuAction()) self.toolBar_2.addSeparator() self.toolBar_2.addAction(self.actionAbrir) self.toolBar_2.addAction(self.actionDocumento) self.toolBar_2.addAction(self.actionAyuda) self.toolBar_2.addAction(self.actionImprimir) self.toolBar_2.addAction(self.actionSalir) self.retranslateUi(MainWindow) self.actionSalir.triggered.connect(MainWindow.close) QtCore.QMetaObject.connectSlotsByName(MainWindow) #---------------------------------------------------------------------- def retranslateUi(self, MainWindow): _translate = QtCore.QCoreApplication.translate MainWindow.setWindowTitle(_translate("MainWindow", "Downloader Mrl")) MainWindow.setStatusTip(_translate("MainWindow", "state of app")) self.Youtube.setWindowTitle(_translate("MainWindow", "Subwindow")) self.menuInicio.setTitle(_translate("MainWindow", "inicio")) self.menuImportar.setStatusTip(_translate("MainWindow", "importar one existent")) self.menuImportar.setTitle(_translate("MainWindow", "import")) self.menuAyuda.setTitle(_translate("MainWindow", "help")) self.toolBar_2.setWindowTitle(_translate("MainWindow", "toolBar_2")) self.toolBar.setWindowTitle(_translate("MainWindow", "toolBar")) self.actionAbrir.setText(_translate("MainWindow", "nuevo")) self.actionAbrir.setStatusTip(_translate("MainWindow", "new proyect")) self.actionAbrir.setShortcut(_translate("MainWindow", "Ctrl+A")) self.actionDocumento.setText(_translate("MainWindow", "documento")) self.actionDocumento.setShortcut(_translate("MainWindow", "Ctrl+N")) self.actionSalir.setText(_translate("MainWindow", "exit")) self.actionAyuda.setText(_translate("MainWindow", "help")) self.actionAcerca.setText(_translate("MainWindow", "about")) self.actionImprimir.setText(_translate("MainWindow", "print")) import icon_rc if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) MainWindow = QtWidgets.QMainWindow() ui = Ui_MainWindow() ui.setupUi(MainWindow) MainWindow.show() sys.exit(app.exec_()) programa.py from program import Ui_MainWindow ######################################################################## class MainWindow(Ui_MainWindow): #---------------------------------------------------------------------- def __init__(self,*args,**kwargs): super(MainWindow,self).__init__(*args,**kwargs) self.setupUi(self) """Constructor""" #------------------------------------------------code execute to press button Imprimir self.actionImprimir.triggered.connect(self.helpo) #---------------------------------------------------------------------- def helpo(self,s): """""" print("hola",s) if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) MainWindow = QtWidgets.QMainWindow() ui = Ui_MainWindow() ui.setupUi(MainWindow) MainWindow.show() sys.exit(app.exec_()) self.actionImprimir.triggered.connect(self.helpo) in this code it makes reference that when I press the button that is related to the other, I execute an impression with the name of: def helpo(self,s): """""" print("hola",s) |