Python - Pyqt: Duplicate output when I use setCurrentIndex - python

When I press the button for go to a diferent page using setCurrentIndex I have problems with duplicate output values because if I set value "1" on QLineEdit on home_page for example and then go to conf_page and now I back to home_page, when I press the OK button for print content of QLineEdit for example, I get a duplicate output.
My code.
Project.py file.
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName(_fromUtf8("Dialog"))
Dialog.resize(210, 191)
self.frame = QtGui.QFrame(Dialog)
self.frame.setGeometry(QtCore.QRect(0, 0, 211, 61))
self.frame.setFrameShape(QtGui.QFrame.StyledPanel)
self.frame.setFrameShadow(QtGui.QFrame.Raised)
self.frame.setObjectName(_fromUtf8("frame"))
self.pushButton_2 = QtGui.QPushButton(self.frame)
self.pushButton_2.setGeometry(QtCore.QRect(20, 20, 75, 23))
self.pushButton_2.setObjectName(_fromUtf8("pushButton_2"))
self.pushButton_3 = QtGui.QPushButton(self.frame)
self.pushButton_3.setGeometry(QtCore.QRect(110, 20, 75, 23))
self.pushButton_3.setObjectName(_fromUtf8("pushButton_3"))
self.stackedWidget = QtGui.QStackedWidget(Dialog)
self.stackedWidget.setGeometry(QtCore.QRect(0, 60, 211, 131))
self.stackedWidget.setObjectName(_fromUtf8("stackedWidget"))
self.page = QtGui.QWidget()
self.page.setObjectName(_fromUtf8("page"))
self.lineEdit = QtGui.QLineEdit(self.page)
self.lineEdit.setGeometry(QtCore.QRect(50, 50, 113, 20))
self.lineEdit.setObjectName(_fromUtf8("lineEdit"))
self.pushButton = QtGui.QPushButton(self.page)
self.pushButton.setGeometry(QtCore.QRect(70, 90, 75, 23))
self.pushButton.setObjectName(_fromUtf8("pushButton"))
self.stackedWidget.addWidget(self.page)
self.page_2 = QtGui.QWidget()
self.page_2.setObjectName(_fromUtf8("page_2"))
self.stackedWidget.addWidget(self.page_2)
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
Dialog.setWindowTitle(_translate("Dialog", "Dialog", None))
self.pushButton_2.setText(_translate("Dialog", "PushButton", None))
self.pushButton_3.setText(_translate("Dialog", "PushButton", None))
self.pushButton.setText(_translate("Dialog", "PushButton", None))
Project.pyw file.
from project import *
import sys
class project(QtGui.QDialog):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_Dialog()
self.ui.setupUi(self)
QtCore.QObject.connect(self.ui.pushButton_2, QtCore.SIGNAL('clicked()'), self.home_page)
QtCore.QObject.connect(self.ui.pushButton_3, QtCore.SIGNAL('clicked()'), self.down_page)
def home_page(self):
self.ui.stackedWidget.setCurrentIndex(0)
QtCore.QObject.connect(self.ui.pushButton, QtCore.SIGNAL('clicked()'), self.output)
def down_page(self):
self.ui.stackedWidget.setCurrentIndex(1)
def output(self):
print(self.ui.lineEdit.text())
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
myapp = project()
myapp.show()
sys.exit(app.exec_())
Any sugestions?
Thanks!!

Related

Pyqt4 age calculator does not output on label

My python/QT (Pyqt4) program is supposed to output a person's age after the calculate button has been pressed, but it doesnt, where have I gone wrong. My code and screenshot of the program when running is hereby attached.
my python code that does not display the text in a label.
this is my .pyw file
import sys
from ass2q2 import *
class MyForm(QtGui.QDialog):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_Dialog()
self.ui.setupUi(self)
QtCore.QObject.connect(self.ui.calculateBtn, QtCore.SIGNAL('clicked()'),self.dispmessage)
def dispmessage(self):
bd=(self.ui.calBD.selectedDate())
curr= QDate.currentDate()
yourAge = bd.daysTo(curr)
self.ui.labelOutput.setText("Your Age (in days) is: " +yourAge.toString())
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
myapp = MyForm()
myapp.show()
sys.exit(app.exec_())
ass2q2.py file
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'ass2q2.ui'
#
# Created by: PyQt4 UI code generator 4.11.4
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName(_fromUtf8("Dialog"))
Dialog.resize(705, 531)
self.calBD = QtGui.QCalendarWidget(Dialog)
self.calBD.setGeometry(QtCore.QRect(40, 150, 280, 155))
self.calBD.setObjectName(_fromUtf8("calBD"))
self.calCurr = QtGui.QCalendarWidget(Dialog)
self.calCurr.setEnabled(False)
self.calCurr.setGeometry(QtCore.QRect(370, 150, 280, 155))
self.calCurr.setObjectName(_fromUtf8("calCurr"))
self.labelbirth = QtGui.QLabel(Dialog)
self.labelbirth.setGeometry(QtCore.QRect(40, 120, 271, 16))
self.labelbirth.setObjectName(_fromUtf8("labelbirth"))
self.labelToDate = QtGui.QLabel(Dialog)
self.labelToDate.setGeometry(QtCore.QRect(380, 120, 261, 21))
self.labelToDate.setObjectName(_fromUtf8("labelToDate"))
self.labelOutput = QtGui.QLabel(Dialog)
self.labelOutput.setGeometry(QtCore.QRect(60, 340, 581, 41))
self.labelOutput.setLineWidth(3)
self.labelOutput.setText(_fromUtf8(""))
self.labelOutput.setObjectName(_fromUtf8("labelOutput"))
self.calculateBtn = QtGui.QPushButton(Dialog)
self.calculateBtn.setGeometry(QtCore.QRect(290, 460, 141, 51))
self.calculateBtn.setObjectName(_fromUtf8("calculateBtn"))
self.labelApp = QtGui.QLabel(Dialog)
self.labelApp.setGeometry(QtCore.QRect(140, 60, 411, 41))
self.labelApp.setObjectName(_fromUtf8("labelApp"))
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
Dialog.setWindowTitle(_translate("Dialog", "Dialog", None))
self.labelbirth.setText(_translate("Dialog", "<html><head/><body><p align=\"center\"><span style=\" font-weight:600;\">Select the Birth Date</span></p></body></html>", None))
self.labelToDate.setText(_translate("Dialog", "<html><head/><body><p align=\"center\"><span style=\" font-weight:600;\">Current Date</span></p></body></html>", None))
self.calculateBtn.setText(_translate("Dialog", "C A L C U L A T E", None))
self.labelApp.setText(_translate("Dialog", "<html><head/><body><p align=\"center\"><span style=\" font-size:12pt; font-weight:600;\">AGE (in days) CALCULATOR</span></p></body></html>", None))

Cant't hide a window when window size maximized in pyqt

i have two windows,i want to hide it after three seconds by using Qt timer,but its overlapping...its probably occurs when window size sets to
"showMaximized"
from PyQt4 import QtCore, QtGui
from PyQt4 import QtGui
from PyQt4.QtCore import Qt, QPoint
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName(_fromUtf8("Form"))
Form.showMaximized()
Form.setStyleSheet(_fromUtf8("background-color: rgb(0, 0, 0);"))
self.label = QtGui.QLabel(Form)
self.label.setGeometry(QtCore.QRect(450, 317, 300, 61))
self.label.setStyleSheet(_fromUtf8("font: 75 60pt \"Tlwg Mono\";color: rgb(255, 255, 255);"))
self.label.setObjectName(_fromUtf8("label"))
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
Form.setWindowTitle(_translate("Form", "Form", None))
self.label.setText(_translate("Form", "omniOS", None))
class Ui_Dialog1(object):
def setupUi(self, Dialog):
Dialog.setObjectName(_fromUtf8("Dialog"))
Dialog.showMaximized()
Dialog.setStyleSheet(_fromUtf8("background-color: rgb(0, 0, 0);"))
QtCore.QMetaObject.connectSlotsByName(Dialog)
self.centralwidget = QtGui.QWidget(Dialog)
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
Dialog.setWindowTitle(_translate("Dialog", "Dialog", None))
class Dialog(QtGui.QDialog, Ui_Form):
def __init__(self, parent=None):
super(Dialog, self).__init__(parent)
self.setupUi(self)
class Dialog1(QtGui.QDialog, Ui_Dialog1):
def __init__(self, parent=None):
super(Dialog1, self).__init__(parent)
self.setupUi(self)
def paintEvent(self, event):
painter = QtGui.QPainter(self)
painter.setPen(QtGui.QPen(QtCore.Qt.white))
painter.drawArc(QtCore.QRectF(640, 330, 35, 35), 0, 5750)
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
w1=Dialog()
w2=Dialog1()
def on_timeout():
w1.hide()
w2.show()
QtCore.QTimer.singleShot(3000, on_timeout)
sys.exit(app.exec_())
what I need to do is, I need to get
second window after three seconds when
size sets to maximized.
Form.showMaximized()
This change to (form.resize) its working what i expected.
Any help plz
You do not observe that w1 is closed because w2 is above w1, but if it is working, so you point out in the comments I understand that you want initially only visible w1 and after 3 seconds w2 is displayed and w1 is hidden, considering that the solution is the following:
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
w1=Dialog()
w2=Dialog1()
w2.hide()
QtCore.QTimer.singleShot(3000, w1.hide)
QtCore.QTimer.singleShot(3000, w2.showMaximized)
sys.exit(app.exec_())

hide a frame after 3 seconds/ by calling a function (need to done in both way)

I create 2 frames in the same window with some attributes in it. now am able to call it separately or can display both
from PyQt4 import QtCore, QtGui
import time
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_Dialog(object):
def frame1(self,Dialog):
self.frame = QtGui.QFrame(Dialog)
self.frame.setGeometry(QtCore.QRect(40, 20, 311, 391))
self.frame.setFrameShape(QtGui.QFrame.StyledPanel)
self.frame.setFrameShadow(QtGui.QFrame.Raised)
self.frame.setObjectName(_fromUtf8("frame"))
self.label = QtGui.QLabel(self.frame)
self.label.setGeometry(QtCore.QRect(120, 180, 72, 23))
self.label.setObjectName(_fromUtf8("label"))
self.label.setText(_translate("Dialog", "omniOS", None))
def frame2(self,Dialog):
self.frame_2 = QtGui.QFrame(Dialog)
self.frame_2.setGeometry(QtCore.QRect(30, 30, 311, 391))
self.frame_2.setFrameShape(QtGui.QFrame.StyledPanel)
self.frame_2.setFrameShadow(QtGui.QFrame.Raised)
self.frame_2.setObjectName(_fromUtf8("frame_2"))
self.label_2 = QtGui.QLabel(self.frame_2)
self.label_2.setGeometry(QtCore.QRect(50, 230, 72, 31))
self.label_2.setObjectName(_fromUtf8("label_2"))
self.lineEdit = QtGui.QLineEdit(self.frame_2)
self.lineEdit.setGeometry(QtCore.QRect(150, 230, 113, 33))
self.lineEdit.setObjectName(_fromUtf8("lineEdit"))
self.label_2.setText(_translate("Dialog", "Login", None))
def setupUi(self, Dialog):
Dialog.setObjectName(_fromUtf8("Dialog"))
Dialog.resize(391, 437)
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
Dialog.setWindowTitle(_translate("Dialog", "OmniOS", None))
self.frame1(Dialog)
self.frame2(Dialog)
if __name__=="__main__":
ui=Ui_Dialog()
import sys
a = QtGui.QApplication(sys.argv)
w = QtGui.QWidget()
ui.setupUi(w)
w.show()
sys.exit(a.exec_())
what I need to do is, I need to get the first window after a 3 second I need to get the second window + hide the first one without overlapping it
self.frame1(Dialog) # call this when the program start
self.frame2(Dialog) # call this after 3 second self.frame1(Dialog)
Any help would be appreciated ThankYou
That a code works does not imply that it is correct, for example I see that you have combined 2 codes generated by Qt Designer and obviously they are going to overlap, the correct thing is to have 2 windows that are exchanged as shown below using QTimer.
from PyQt4 import QtCore, QtGui
import time
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_Dialog1(object):
def setupUi(self, Dialog):
self.frame = QtGui.QFrame(Dialog)
self.frame.setGeometry(QtCore.QRect(40, 20, 311, 391))
self.frame.setFrameShape(QtGui.QFrame.StyledPanel)
self.frame.setFrameShadow(QtGui.QFrame.Raised)
self.frame.setObjectName(_fromUtf8("frame"))
self.label = QtGui.QLabel(self.frame)
self.label.setGeometry(QtCore.QRect(120, 180, 72, 23))
self.label.setObjectName(_fromUtf8("label"))
self.label.setText(_translate("Dialog", "omniOS", None))
Dialog.setObjectName(_fromUtf8("Dialog"))
Dialog.resize(391, 437)
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
Dialog.setWindowTitle(_translate("Dialog", "OmniOS", None))
class Ui_Dialog2(object):
def setupUi(self, Dialog):
self.frame_2 = QtGui.QFrame(Dialog)
self.frame_2.setGeometry(QtCore.QRect(30, 30, 311, 391))
self.frame_2.setFrameShape(QtGui.QFrame.StyledPanel)
self.frame_2.setFrameShadow(QtGui.QFrame.Raised)
self.frame_2.setObjectName(_fromUtf8("frame_2"))
self.label_2 = QtGui.QLabel(self.frame_2)
self.label_2.setGeometry(QtCore.QRect(50, 230, 72, 31))
self.label_2.setObjectName(_fromUtf8("label_2"))
self.lineEdit = QtGui.QLineEdit(self.frame_2)
self.lineEdit.setGeometry(QtCore.QRect(150, 230, 113, 33))
self.lineEdit.setObjectName(_fromUtf8("lineEdit"))
self.label_2.setText(_translate("Dialog", "Login", None))
Dialog.setObjectName(_fromUtf8("Dialog"))
Dialog.resize(391, 437)
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
self.retranslateUi(Dialog)
def retranslateUi(self, Dialog):
Dialog.setWindowTitle(_translate("Dialog", "OmniOS", None))
class Dialog1(QtGui.QDialog, Ui_Dialog1):
def __init__(self, parent=None):
super(Dialog1, self).__init__(parent)
self.setupUi(self)
class Dialog2(QtGui.QDialog, Ui_Dialog2):
def __init__(self, parent=None):
super(Dialog2, self).__init__(parent)
self.setupUi(self)
if __name__=="__main__":
import sys
a = QtGui.QApplication(sys.argv)
w1 = Dialog1()
w2 = Dialog2()
def on_timeout():
w1.hide()
w2.show()
w1.show()
QtCore.QTimer.singleShot(3000, on_timeout)
sys.exit(a.exec_())

PyQt transferring a list between dialog and window

Very much a beginner on the UI side of things!
I'm trying to transfer a list from a dialog to the main window (when a button is pressed) and then transfer a new list back to the window when the dialog is accepted.
Here's a MWE of what I'm working on to give you an idea.
It should print out the following,
Desired output:
[b]
.
[b]
[a]
.
[a]
Achieved output:
[b]
.
[b]
[a]
.
[b]
Thanks in advance!
MWE:
import sys
from PyQt4 import QtCore, QtGui#pyqt5, QtWidgets
from Scrabble_gui import Ui_MainWindow
from Input_letters_gui import Ui_Dialog as Popup
class ScrabbleGuiProgram(Ui_MainWindow):
def __init__(self, dialog):
Ui_MainWindow.__init__(self)
self.setupUi(dialog)
self.In_letters.clicked.connect(self.Input_letters)
def Input_letters(self):
"""Prints "b" and opens pop up.
after popup is closed, prints "a"
"""
letter_list = ["b"]
#app = QtGui.QApplication(sys.argv)
print(letter_list)
print(".")
PUDialog = QtGui.QDialog()
pop = Input_letters_popup(PUDialog, letter_list)
PUDialog.exec_()
print(".")
print(letter_list)
class Input_letters_popup(Popup):
def __init__(self, dialog, letter_list):
"""when open prints incoming list ("b")
"""
print(letter_list)
Popup.__init__(self)
self.setupUi(dialog)
self.buttonBox.accepted.connect(self.Get_letters)#lambda: self.Get_letters)
#self.buttonBox.rejected.connect()
def Get_letters(self):
"""on popup exit prints new list ("a")
"""
letters = ["a"]
print(letters)
return letters
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
Dialog = QtGui.QMainWindow()
prog = ScrabbleGuiProgram(Dialog)#Input_letters_popup(Dialog)
Dialog.show()
sys.exit(app.exec_())
Scrabble_gui.py
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'Scrabble.ui'
#
# Created by: PyQt4 UI code generator 4.11.4
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName(_fromUtf8("MainWindow"))
MainWindow.resize(406, 267)
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
self.Gen_words = QtGui.QPushButton(self.centralwidget)
self.Gen_words.setGeometry(QtCore.QRect(250, 20, 121, 28))
self.Gen_words.setObjectName(_fromUtf8("Gen_words"))
self.Long_word = QtGui.QLineEdit(self.centralwidget)
self.Long_word.setGeometry(QtCore.QRect(229, 100, 141, 22))
self.Long_word.setReadOnly(True)
self.Long_word.setObjectName(_fromUtf8("Long_word"))
self.label_2 = QtGui.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(279, 180, 41, 21))
self.label_2.setObjectName(_fromUtf8("label_2"))
self.label_3 = QtGui.QLabel(self.centralwidget)
self.label_3.setGeometry(QtCore.QRect(99, 143, 131, 21))
self.label_3.setObjectName(_fromUtf8("label_3"))
self.High_score = QtGui.QLineEdit(self.centralwidget)
self.High_score.setGeometry(QtCore.QRect(319, 180, 51, 22))
self.High_score.setReadOnly(True)
self.High_score.setObjectName(_fromUtf8("High_score"))
self.High_word = QtGui.QLineEdit(self.centralwidget)
self.High_word.setGeometry(QtCore.QRect(229, 143, 141, 22))
self.High_word.setReadOnly(True)
self.High_word.setObjectName(_fromUtf8("High_word"))
self.In_letters = QtGui.QPushButton(self.centralwidget)
self.In_letters.setGeometry(QtCore.QRect(90, 57, 121, 28))
self.In_letters.setObjectName(_fromUtf8("In_letters"))
self.Gen_letters = QtGui.QPushButton(self.centralwidget)
self.Gen_letters.setGeometry(QtCore.QRect(90, 20, 121, 28))
self.Gen_letters.setObjectName(_fromUtf8("Gen_letters"))
self.letters = QtGui.QListWidget(self.centralwidget)
self.letters.setGeometry(QtCore.QRect(20, 50, 41, 161))
self.letters.setObjectName(_fromUtf8("letters"))
self.label = QtGui.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(145, 100, 81, 20))
self.label.setObjectName(_fromUtf8("label"))
self.label_4 = QtGui.QLabel(self.centralwidget)
self.label_4.setGeometry(QtCore.QRect(20, 20, 41, 21))
self.label_4.setObjectName(_fromUtf8("label_4"))
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtGui.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 406, 26))
self.menubar.setObjectName(_fromUtf8("menubar"))
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtGui.QStatusBar(MainWindow)
self.statusbar.setObjectName(_fromUtf8("statusbar"))
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(_translate("MainWindow", "Descrabbler", None))
self.Gen_words.setText(_translate("MainWindow", "Best Words", None))
self.label_2.setText(_translate("MainWindow", "Score", None))
self.label_3.setText(_translate("MainWindow", "Highest Scoring Word", None))
self.In_letters.setText(_translate("MainWindow", "Input Letters", None))
self.Gen_letters.setText(_translate("MainWindow", "Generate Letters", None))
self.label.setText(_translate("MainWindow", "Longest Word", None))
self.label_4.setText(_translate("MainWindow", "Letters", None))
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
MainWindow = QtGui.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
Input_letters_gui.py
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'Input_letters.ui'
#
# Created by: PyQt4 UI code generator 4.11.4
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName(_fromUtf8("Dialog"))
Dialog.resize(400, 173)
self.buttonBox = QtGui.QDialogButtonBox(Dialog)
self.buttonBox.setGeometry(QtCore.QRect(30, 90, 341, 32))
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
self.buttonBox.setObjectName(_fromUtf8("buttonBox"))
self.ltr1 = QtGui.QLineEdit(Dialog)
self.ltr1.setGeometry(QtCore.QRect(20, 40, 31, 22))
self.ltr1.setObjectName(_fromUtf8("ltr1"))
self.ltr2 = QtGui.QLineEdit(Dialog)
self.ltr2.setGeometry(QtCore.QRect(60, 40, 31, 22))
self.ltr2.setObjectName(_fromUtf8("ltr2"))
self.ltr3 = QtGui.QLineEdit(Dialog)
self.ltr3.setGeometry(QtCore.QRect(100, 40, 31, 22))
self.ltr3.setObjectName(_fromUtf8("ltr3"))
self.ltr4 = QtGui.QLineEdit(Dialog)
self.ltr4.setGeometry(QtCore.QRect(140, 40, 31, 22))
self.ltr4.setObjectName(_fromUtf8("ltr4"))
self.ltr5 = QtGui.QLineEdit(Dialog)
self.ltr5.setGeometry(QtCore.QRect(180, 40, 31, 22))
self.ltr5.setObjectName(_fromUtf8("ltr5"))
self.ltr6 = QtGui.QLineEdit(Dialog)
self.ltr6.setGeometry(QtCore.QRect(220, 40, 31, 22))
self.ltr6.setObjectName(_fromUtf8("ltr6"))
self.ltr7 = QtGui.QLineEdit(Dialog)
self.ltr7.setGeometry(QtCore.QRect(260, 40, 31, 22))
self.ltr7.setObjectName(_fromUtf8("ltr7"))
self.retranslateUi(Dialog)
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("accepted()")), Dialog.accept)
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("rejected()")), Dialog.reject)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
Dialog.setWindowTitle(_translate("Dialog", "Input Letters", None))
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
Dialog = QtGui.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog)
Dialog.show()
sys.exit(app.exec_())

Pyqt4 MainWindow->Form->Form impossible?

i want to display form after form that is display after mainwindow.
This is my code. I success display form after mainwindow.
but MainWindow->Form->Form not work....
please help my brain
my brain is very hot...
main.py
class main(QtGui.QMainWindow):
def __init__(self,parent=None):
QtGui.QWidget.__init__(self,parent)
self.ui=Ui_MainWindow()
self.ui.setupUi(self)
app=QtGui.QApplication(sys.argv)
myapp=main()
myapp.show()
app.exec_()
mainUI.py
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'main.ui'
#
# Created: Tue Mar 17 17:24:48 2015
# by: PyQt4 UI code generator 4.11.3
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
import thread
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
def start(msg):
while 1:
None
def start2(msg):
while 1:
None
global Form
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName(_fromUtf8("MainWindow"))
MainWindow.resize(722, 265)
MainWindow.setMinimumSize(QtCore.QSize(722, 265))
MainWindow.setMaximumSize(QtCore.QSize(722, 265))
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap(_fromUtf8("image/images.jpg")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
MainWindow.setWindowIcon(icon)
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
self.label = QtGui.QLabel(self.centralwidget)
self.label.setEnabled(True)
self.label.setGeometry(QtCore.QRect(-30, -50, 751, 341))
self.label.setMouseTracking(False)
self.label.setAcceptDrops(False)
self.label.setText(_fromUtf8(""))
self.label.setPixmap(QtGui.QPixmap(_fromUtf8("image/main.png")))
self.label.setObjectName(_fromUtf8("label"))
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtGui.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 722, 21))
self.menubar.setObjectName(_fromUtf8("menubar"))
self.menu = QtGui.QMenu(self.menubar)
self.menu.setObjectName(_fromUtf8("menu"))
MainWindow.setMenuBar(self.menubar)
self.action = QtGui.QAction(MainWindow)
self.action.setObjectName(_fromUtf8("action"))
self.menu.addAction(self.action)
self.menubar.addAction(self.menu.menuAction())
self.retranslateUi(MainWindow)
QtCore.QObject.connect(self.action, QtCore.SIGNAL(_fromUtf8("triggered()")), self.create_child)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def create_child(self):
#here put the code that creates the new window and shows it.
global Form
Form=QtGui.QWidget()
child = release_Form()
child.setupReleaseUi(Form)
thread.start_new_thread(start,(Form,))
Form.show()
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(_translate("MainWindow", "Smart Update", None))
self.menu.setTitle(_translate("MainWindow", "릴리즈노트", None))
self.action.setText(_translate("MainWindow", "릴리즈노트", None))
class release_Form(object):
def setupReleaseUi(self, Form):
Form.setObjectName(_fromUtf8("Form"))
Form.resize(499, 406)
self.New = QtGui.QPlainTextEdit(Form)
self.New.setGeometry(QtCore.QRect(20, 20, 104, 301))
self.New.setObjectName(_fromUtf8("New"))
self.Modify = QtGui.QPlainTextEdit(Form)
self.Modify.setGeometry(QtCore.QRect(150, 20, 104, 301))
self.Modify.setObjectName(_fromUtf8("Modify"))
self.Delete = QtGui.QPlainTextEdit(Form)
self.Delete.setGeometry(QtCore.QRect(280, 20, 104, 301))
self.Delete.setObjectName(_fromUtf8("Delete"))
self.pushButton = QtGui.QPushButton(Form)
self.pushButton.setGeometry(QtCore.QRect(410, 70, 75, 23))
self.pushButton.setObjectName(_fromUtf8("pushButton"))
self.retranslateUi(Form)
QtCore.QObject.connect(self.New, QtCore.SIGNAL(_fromUtf8("textChanged()")), self.Modify.clear)
QtCore.QObject.connect(self.Modify, QtCore.SIGNAL(_fromUtf8("textChanged()")), self.New.centerCursor)
QtCore.QObject.connect(self.Delete, QtCore.SIGNAL(_fromUtf8("textChanged()")), self.Delete.centerCursor)
QtCore.QObject.connect(self.pushButton, QtCore.SIGNAL(_fromUtf8("clicked()")), self.create_alert)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
Form.setWindowTitle(_translate("Form", "Form", None))
def create_alert(self):
global Form
Form1=QtGui.QWidget()
alert_Form.show()
child1 = alert_Form()
child1.setupAlertUi(Form1)
thread.start_new_thread(start2,(Form,))
Form1.show()
class alert_Form(object):
def setupAlertUi(self, Form):
Form.setObjectName(_fromUtf8("Form"))
Form.resize(431, 109)
Form.setMinimumSize(QtCore.QSize(431, 109))
Form.setMaximumSize(QtCore.QSize(431, 109))
self.label = QtGui.QLabel(Form)
self.label.setGeometry(QtCore.QRect(-10, -10, 451, 121))
self.label.setText(_fromUtf8(""))
self.label.setPixmap(QtGui.QPixmap(_fromUtf8("image/alert.png")))
self.label.setScaledContents(True)
self.label.setAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft|QtCore.Qt.AlignTop)
self.label.setObjectName(_fromUtf8("label"))
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
Form.setWindowTitle(_translate("Form", "Alert", None))
you should connect function.
and you call other Form like this
if you want only once call Form, remove thread.
def create_setting(self):
global Dialog
Dialog=QtGui.QDialog()
thread.start_new_thread(start,(Dialog,))
child = settingUI.Ui_Form()
child.setupUi(Dialog)
Dialog.setWindowFlags(Dialog.windowFlags()|QtCore.Qt.WindowSystemMenuHint|QtCore.Qt.WindowMinMaxButtonsHint)
Dialog.show()

Categories