This is a simplified version of a bigger program.
I made a GUI with the help of Qt Designer. Here is it:
The main window has two Frames, frame_1 and frame_2. First screen (frame_1) is the main window and contains just a pushbutton to open the second screen. The second screeen (frame_2) contains a lineEdit and two buttons. Here is the Python code to use the GUI:
from PyQt5 import uic, QtWidgets
import sys, os
def screen2():
myApp.frame_1.close()
myApp.frame_2.show()
myApp.pushButton_2.clicked.connect(add_name)
myApp.pushButton_3.clicked.connect(close_screen2)
def add_name():
name = myApp.lineEdit.text()
print(name)
def close_screen2():
myApp.lineEdit.setText('')
myApp.frame_2.close()
myApp.frame_1.show()
app = QtWidgets.QApplication.instance()
if app is None:
app = QtWidgets.QApplication(sys.argv)
myApp = uic.loadUi('myApp.ui')
myApp.show()
myApp.frame_2.close()
myApp.pushButton.clicked.connect(screen2)
app.exec_()
The program start with the main screen. The user click the button to open the second screen. Then he enter a name in the lineEdit and then click on Ok. The name will be assigned to a variable name and then printed. For the last, the user click on Close to return to the main sreen.
I made a test by open the second screen, entering a name and closing the screen, by three times. Here is the results:
Name1
Name2
Name2
Name3
Name3
Name3
One can see that in the first run the name entered is printed once. In the second run it's printed twice. In third run it's printed three times. It seems that something don't stopped after the first run so that in the second run two things happen at the same time and in the third run three things happen at the same time. what is going on? Someone could explain me?