pyqt дочерние окна
Не могу ничего найти толкового. Хочу сделать в pyqt чтобы по нажатию кнопки в форме, открылась другая форма дочерняя. Вот для этого создал два ui1.py и ui2.py И вот как тепер мне сделать чтобы открылась ui2 из ui1? Пробовал импортировать, делать show() для класса формы, брал советы из форумов, ничего не получается( должен же быть какой-нибудь простой действенный способ. Подскажите добрые люди, пожалуйста_)
# -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'edit_cards.ui' # # Created: Sun Apr 12 21:42:11 2015 # by: PyQt4 UI code generator 4.9.1 # # WARNING! All changes made in this file will be lost! import os import sys import sqlite3 as db from PyQt4 import QtCore, QtGui, QtSql from PyQt4.QtCore import QStringList, QString from PyQt4.QtGui import QApplication, QMainWindow, QSizePolicy from PyQt4.QtGui import QTableWidget, QTableWidgetItem import re try: _fromUtf8 = QtCore.QString.fromUtf8 except AttributeError: _fromUtf8 = lambda s: s class Ui_Card_dialog(object): def setupUi(self, Card_dialog): Card_dialog.setObjectName(_fromUtf8("Card_dialog")) Card_dialog.resize(370, 577) Card_dialog.setLocale(QtCore.QLocale(QtCore.QLocale.Russian, QtCore.QLocale.RussianFederation)) self.verticalLayout = QtGui.QVBoxLayout(Card_dialog) self.verticalLayout.setObjectName(_fromUtf8("verticalLayout")) self.label = QtGui.QLabel(Card_dialog) font = QtGui.QFont() font.setPointSize(12) self.label.setFont(font) self.label.setObjectName(_fromUtf8("label")) self.verticalLayout.addWidget(self.label) self.manufac_lineEdit = QtGui.QLineEdit(Card_dialog) font = QtGui.QFont() font.setPointSize(12) self.manufac_lineEdit.setFont(font) self.manufac_lineEdit.setObjectName(_fromUtf8("manufac_lineEdit")) self.verticalLayout.addWidget(self.manufac_lineEdit) self.label_2 = QtGui.QLabel(Card_dialog) font = QtGui.QFont() font.setPointSize(12) self.label_2.setFont(font) self.label_2.setObjectName(_fromUtf8("label_2")) self.verticalLayout.addWidget(self.label_2) self.name_lineEdit = QtGui.QLineEdit(Card_dialog) font = QtGui.QFont() font.setPointSize(12) self.name_lineEdit.setFont(font) self.name_lineEdit.setObjectName(_fromUtf8("name_lineEdit")) self.verticalLayout.addWidget(self.name_lineEdit) self.label_3 = QtGui.QLabel(Card_dialog) font = QtGui.QFont() font.setPointSize(12) self.label_3.setFont(font) self.label_3.setObjectName(_fromUtf8("label_3")) self.verticalLayout.addWidget(self.label_3) self.unit_comboBox = QtGui.QComboBox(Card_dialog) font = QtGui.QFont() font.setPointSize(12) self.unit_comboBox.setFont(font) self.unit_comboBox.setObjectName(_fromUtf8("unit_comboBox")) self.unit_comboBox.addItem(_fromUtf8("")) self.unit_comboBox.addItem(_fromUtf8("")) self.unit_comboBox.addItem(_fromUtf8("")) self.unit_comboBox.addItem(_fromUtf8("")) self.unit_comboBox.addItem(_fromUtf8("")) self.unit_comboBox.addItem(_fromUtf8("")) self.verticalLayout.addWidget(self.unit_comboBox) self.label_4 = QtGui.QLabel(Card_dialog) font = QtGui.QFont() font.setPointSize(12) self.label_4.setFont(font) self.label_4.setObjectName(_fromUtf8("label_4")) self.verticalLayout.addWidget(self.label_4) self.NDS_comboBox = QtGui.QComboBox(Card_dialog) font = QtGui.QFont() font.setPointSize(12) self.NDS_comboBox.setFont(font) self.NDS_comboBox.setObjectName(_fromUtf8("NDS_comboBox")) self.NDS_comboBox.addItem(_fromUtf8("")) self.NDS_comboBox.addItem(_fromUtf8("")) self.NDS_comboBox.addItem(_fromUtf8("")) self.verticalLayout.addWidget(self.NDS_comboBox) self.label_6 = QtGui.QLabel(Card_dialog) font = QtGui.QFont() font.setPointSize(12) self.label_6.setFont(font) self.label_6.setObjectName(_fromUtf8("label_6")) self.verticalLayout.addWidget(self.label_6) self.RU_lineEdit = QtGui.QLineEdit(Card_dialog) font = QtGui.QFont() font.setPointSize(12) self.RU_lineEdit.setFont(font) self.RU_lineEdit.setObjectName(_fromUtf8("RU_lineEdit")) self.verticalLayout.addWidget(self.RU_lineEdit) self.label_5 = QtGui.QLabel(Card_dialog) font = QtGui.QFont() font.setPointSize(12) self.label_5.setFont(font) self.label_5.setObjectName(_fromUtf8("label_5")) self.verticalLayout.addWidget(self.label_5) self.calendarWidget = QtGui.QCalendarWidget(Card_dialog) font = QtGui.QFont() font.setPointSize(12) self.calendarWidget.setFont(font) self.calendarWidget.setObjectName(_fromUtf8("calendarWidget")) self.verticalLayout.addWidget(self.calendarWidget) self.retranslateUi(Card_dialog) QtCore.QMetaObject.connectSlotsByName(Card_dialog) def retranslateUi(self, Card_dialog): Card_dialog.setWindowTitle(QtGui.QApplication.translate("Card_dialog", "Карточка товара", None, QtGui.QApplication.UnicodeUTF8)) self.label.setText(QtGui.QApplication.translate("Card_dialog", "Прозводитель", None, QtGui.QApplication.UnicodeUTF8)) self.label_2.setText(QtGui.QApplication.translate("Card_dialog", "Наименование", None, QtGui.QApplication.UnicodeUTF8)) self.label_3.setText(QtGui.QApplication.translate("Card_dialog", "Единица измерения", None, QtGui.QApplication.UnicodeUTF8)) self.unit_comboBox.setItemText(0, QtGui.QApplication.translate("Card_dialog", "Упаковка", None, QtGui.QApplication.UnicodeUTF8)) self.unit_comboBox.setItemText(1, QtGui.QApplication.translate("Card_dialog", "Килограммы", None, QtGui.QApplication.UnicodeUTF8)) self.unit_comboBox.setItemText(2, QtGui.QApplication.translate("Card_dialog", "Штуки", None, QtGui.QApplication.UnicodeUTF8)) self.unit_comboBox.setItemText(3, QtGui.QApplication.translate("Card_dialog", "Литры", None, QtGui.QApplication.UnicodeUTF8)) self.unit_comboBox.setItemText(4, QtGui.QApplication.translate("Card_dialog", "Наборы", None, QtGui.QApplication.UnicodeUTF8)) self.unit_comboBox.setItemText(5, QtGui.QApplication.translate("Card_dialog", "Флаконы", None, QtGui.QApplication.UnicodeUTF8)) self.label_4.setText(QtGui.QApplication.translate("Card_dialog", "Ставка НДС", None, QtGui.QApplication.UnicodeUTF8)) self.NDS_comboBox.setItemText(0, QtGui.QApplication.translate("Card_dialog", "10", None, QtGui.QApplication.UnicodeUTF8)) self.NDS_comboBox.setItemText(1, QtGui.QApplication.translate("Card_dialog", "18", None, QtGui.QApplication.UnicodeUTF8)) self.NDS_comboBox.setItemText(2, QtGui.QApplication.translate("Card_dialog", "Без НДС", None, QtGui.QApplication.UnicodeUTF8)) self.label_6.setText(QtGui.QApplication.translate("Card_dialog", "№ РУ", None, QtGui.QApplication.UnicodeUTF8)) self.label_5.setText(QtGui.QApplication.translate("Card_dialog", "Дата окнчания РУ", None, QtGui.QApplication.UnicodeUTF8)) def show_me(): window = Ui_Card_dialog() window.show() return window #if __name__ == "__main__": # app = QtGui.QApplication(sys.argv) # Form = QtGui.QWidget() # ex = Ui_Card_dialog() # ex.setupUi(Form) # Form.show() # app.exec_()
# -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'table_cards.ui' # # Created: Sun Apr 12 21:42:36 2015 # by: PyQt4 UI code generator 4.9.1 # # WARNING! All changes made in this file will be lost! import os import sys import sqlite3 as db from PyQt4 import QtCore, QtGui, QtSql from PyQt4.QtCore import QStringList, QString from PyQt4.QtGui import QApplication, QMainWindow, QSizePolicy from PyQt4.QtGui import QTableWidget, QTableWidgetItem import re import edit_cards try: _fromUtf8 = QtCore.QString.fromUtf8 except AttributeError: _fromUtf8 = lambda s: s class Ui_Dialog_cards(object): def setupUi(self, Dialog_cards): Dialog_cards.setObjectName(_fromUtf8("Dialog_cards")) Dialog_cards.resize(826, 518) self.gridLayout = QtGui.QGridLayout(Dialog_cards) self.gridLayout.setObjectName(_fromUtf8("gridLayout")) self.tableWidget_cards = QtGui.QTableWidget(Dialog_cards) font = QtGui.QFont() font.setPointSize(12) self.tableWidget_cards.setFont(font) self.tableWidget_cards.setObjectName(_fromUtf8("tableWidget_cards")) self.tableWidget_cards.setColumnCount(0) self.tableWidget_cards.setRowCount(0) self.gridLayout.addWidget(self.tableWidget_cards, 0, 0, 1, 3) self.Change_Button = QtGui.QPushButton(Dialog_cards) font = QtGui.QFont() font.setPointSize(12) self.Change_Button.setFont(font) self.Change_Button.setObjectName(_fromUtf8("Change_Button")) self.gridLayout.addWidget(self.Change_Button, 2, 0, 1, 1) self.Delete_Button = QtGui.QPushButton(Dialog_cards) font = QtGui.QFont() font.setPointSize(12) self.Delete_Button.setFont(font) self.Delete_Button.setObjectName(_fromUtf8("Delete_Button")) self.gridLayout.addWidget(self.Delete_Button, 2, 1, 1, 1) self.Close_Button = QtGui.QPushButton(Dialog_cards) font = QtGui.QFont() font.setPointSize(12) self.Close_Button.setFont(font) self.Close_Button.setObjectName(_fromUtf8("Close_Button")) self.gridLayout.addWidget(self.Close_Button, 2, 2, 1, 1) self.retranslateUi(Dialog_cards) QtCore.QMetaObject.connectSlotsByName(Dialog_cards) def retranslateUi(self, Dialog_cards): Dialog_cards.setWindowTitle(QtGui.QApplication.translate("Dialog_cards", "Товары", None, QtGui.QApplication.UnicodeUTF8)) self.Change_Button.setText(QtGui.QApplication.translate("Dialog_cards", "Изменить товар", None, QtGui.QApplication.UnicodeUTF8)) QtCore.QObject.connect(self.Change_Button, QtCore.SIGNAL('clicked()'), self.show_edit_window) self.Delete_Button.setText(QtGui.QApplication.translate("Dialog_cards", "Удалить товар", None, QtGui.QApplication.UnicodeUTF8)) self.Close_Button.setText(QtGui.QApplication.translate("Dialog_cards", "Закрыть", None, QtGui.QApplication.UnicodeUTF8)) def show_edit_window(self): import edit_cards print 'lol' edit_cards.show_me() if __name__ == "__main__": app = QtGui.QApplication(sys.argv) Form = QtGui.QWidget() ex = Ui_Dialog_cards() ex.setupUi(Form) Form.show() app.exec_()
Как сделать дочернее окно?
Как сделать дочернее окно, что бы из него можно было передать значения переменных?
Всем здравствуйте, если кто-то знает, напишите пожалуйста)
Есть главное меню с QPushButton и QTextBrowser
Надо, что бы через QPushButton открывалось окно с полем ввода имени и с кнопкой (сохранить), после чего, при нажатии на кнопку (сохранить) окно закрывалось и имя, которое ввели в поле ввода, вывелось в QTextBrowser в главном окне)
Объяснил, как бог)))
import os import sys from PyQt5.QtWidgets import * from PyQt5.QtCore import * def log_uncaught_exceptions(ex_cls, ex, tb): import traceback text = '<>: <>:\n\n'.format(ex_cls.__name__, ex) text += ''.join(traceback.format_tb(tb)) QMessageBox.critical(None, 'Ошибка!', text) sys.excepthook = log_uncaught_exceptions class EnterName(QWidget): text_value = pyqtSignal(str) def __init__(self): super().__init__() self.initUI() def initUI(self): self.setGeometry(300, 300, 300, 50) self.setWindowTitle('Введите имя') self.button = QPushButton('Сохранить', self) self.button.clicked.connect(self.bEvent) self.button.move(120, 30) self.lEdid = QLineEdit(self) self.lEdid.setGeometry(0, 0, 300, 30) @pyqtSlot() def bEvent(self): self.text_value.emit(self.lEdid.text()) self.hide() class Example(QWidget): def __init__(self): super().__init__() self.initUI() def initUI(self): self.setGeometry(300, 300, 420, 280) self.setWindowTitle('Exsample') self.button = QPushButton('Имя', self) self.button.move(180, 260) self.button.clicked.connect(self.bEvent) self.tb = QTextBrowser(self) self.tb.setGeometry(0, 0, 420, 260) self.eName = EnterName() self.eName.text_value.connect(self.signalHandler) def bEvent(self): self.eName.show() def signalHandler(self, text): self.tb.append(text) if __name__ == '__main__': app = QApplication(sys.argv) example = Example() example.show() sys.exit(app.exec_())