maximum recursion depth exceeded in python multiple dialog - python

# -*- coding: utf-8 -*-
import sys
from PyQt4 import QtGui, QtCore
class Window_Test3(QtGui.QDialog):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
global progress_flag
**self.Next_Window = Window_Test1() # Return Window_Test1() but RuntimeError: maximum recursion depth exceeded**
self.setWindowFlags(QtCore.Qt.CustomizeWindowHint|QtCore.Qt.WindowTitleHint|QtCore.Qt.WindowMaximizeButtonHint)
self.setGeometry(0, 0, 800,480)
self.setWindowTitle('TEST PROCESSING')
quit = QtGui.QPushButton('Close', self)
quit.setGeometry(10, 10, 60, 35)
test = QtGui.QPushButton('TEST 3', self)
test.setGeometry(100, 200, 200, 100)
self.connect(quit, QtCore.SIGNAL('clicked()'),self.reject)
self.connect(test, QtCore.SIGNAL('clicked()'), self.nextWindow)
def nextWindow(self):
self.Next_Window.show()
class Window_Test2(QtGui.QDialog):
def __init__(self):
QtGui.QWidget.__init__(self)
global progress_flag
self.Window3 = Window_Test3()
self.setWindowFlags(QtCore.Qt.CustomizeWindowHint|QtCore.Qt.WindowTitleHint|QtCore.Qt.WindowMaximizeButtonHint)
self.setGeometry(0, 0, 800, 480)
self.setWindowTitle('TEST PROCESSING')
self.quit = QtGui.QPushButton('Close', self)
self.quit.setGeometry(10, 10, 60, 35)
test = QtGui.QPushButton('TEST 2', self)
test.setGeometry(250, 220, 200, 100)
self.connect(self.quit, QtCore.SIGNAL('clicked()'),self.reject)
self.connect(test, QtCore.SIGNAL('clicked()'),self.nextWindow)
def nextWindow(self):
self.Window3.show()
class Window_Test1(QtGui.QDialog):
def __init__(self):
QtGui.QWidget.__init__(self)
self.Window2 = Window_Test2()
self.setGeometry(0, 0, 800, 480)
self.setWindowTitle('TEST PROCESSING' )
test = QtGui.QPushButton('TEST', self)
test.setGeometry(100,100,100,100)
quit = QtGui.QPushButton('Close', self)
quit.setGeometry(10, 10, 60, 35)
self.connect(test, QtCore.SIGNAL('clicked()'),self.nextWindow)
self.connect(quit, QtCore.SIGNAL('clicked()'), self.reject)
def nextWindow(self):
self.Window2.show()
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
Window1 = Window_Test1()
Window1.show()
sys.exit(app.exec_())

Your code recursively initializes new objects.
Window_Test1 calls Window_Test2, which calls Window_Test3, which calls Window_Test1, which calls Window_Test2, which calls Window_Test3, which calls Window_Test1, which... you get the point.
You'll want to either defer the initialization of those objects to when they're actually needed (so not in __init__), or maybe have single instances of all three windows that are referred to.

Create a placeholder self.next_Window for the next window and fill it in after creating all 3 windows
# -*- coding: utf-8 -*-
import sys
from PyQt4 import QtGui, QtCore
class Window_Test3(QtGui.QDialog):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
global progress_flag
self.next_Window = None
self.setWindowFlags(QtCore.Qt.CustomizeWindowHint|
QtCore.Qt.WindowTitleHint|
QtCore.Qt.WindowMaximizeButtonHint)
self.setGeometry(0, 0, 800,480)
self.setWindowTitle('TEST PROCESSING')
quit = QtGui.QPushButton('Close', self)
quit.setGeometry(10, 10, 60, 35)
test = QtGui.QPushButton('TEST 3', self)
test.setGeometry(100, 200, 200, 100)
self.connect(quit, QtCore.SIGNAL('clicked()'),self.reject)
self.connect(test, QtCore.SIGNAL('clicked()'), self.nextWindow)
def nextWindow(self):
self.next_Window.show()
def setNextWindow(self, nextWindow):
self.next_Window = nextWindow
class Window_Test2(QtGui.QDialog):
def __init__(self):
QtGui.QWidget.__init__(self)
global progress_flag
self.next_Window = None
self.setWindowFlags(QtCore.Qt.CustomizeWindowHint|
QtCore.Qt.WindowTitleHint|
QtCore.Qt.WindowMaximizeButtonHint)
self.setGeometry(0, 0, 800, 480)
self.setWindowTitle('TEST PROCESSING')
self.quit = QtGui.QPushButton('Close', self)
self.quit.setGeometry(10, 10, 60, 35)
test = QtGui.QPushButton('TEST 2', self)
test.setGeometry(250, 220, 200, 100)
self.connect(self.quit, QtCore.SIGNAL('clicked()'),self.reject)
self.connect(test, QtCore.SIGNAL('clicked()'),self.nextWindow)
def nextWindow(self):
self.next_Window.show()
def setNextWindow(self, nextWindow):
self.next_Window = nextWindow
class Window_Test1(QtGui.QDialog):
def __init__(self):
QtGui.QWidget.__init__(self)
self.next_Window = None
self.setGeometry(0, 0, 800, 480)
self.setWindowTitle('TEST PROCESSING' )
test = QtGui.QPushButton('TEST', self)
test.setGeometry(100,100,100,100)
quit = QtGui.QPushButton('Close', self)
quit.setGeometry(10, 10, 60, 35)
self.connect(test, QtCore.SIGNAL('clicked()'),self.nextWindow)
self.connect(quit, QtCore.SIGNAL('clicked()'), self.reject)
def nextWindow(self):
self.next_Window.show()
def setNextWindow(self, nextWindow):
self.next_Window = nextWindow
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
Window1 = Window_Test1()
Window2 = Window_Test2()
Window3 = Window_Test3()
Window1.setNextWindow(Window2)
Window2.setNextWindow(Window3)
Window3.setNextWindow(Window1)
Window1.show()
sys.exit(app.exec_())

There should be only one window instead of three.
def nextWindow (self):
self.next_Window.show()
self.actionEvent (self.reject ()) # Delete current screen
def setNextWindow (self, nextWindow):
self.next_Window = nextWindow
That is, you add self.actionEvent(self.reject ()),
One screen is output.
However, there is a slight jitter when switching the screen.

Related

PyQT: Exit/Complete Second Window Before First Window

I have the following code below:
from PyQt4 import QtGui
import sys
class Second(QtGui.QWidget):
def __init__(self, parent=None):
super(Second, self).__init__(parent)
self.grid = QtGui.QGridLayout(self)
self.setGeometry(650,400,400,200)
self.widget = QtGui.QWidget()
class First(QtGui.QMainWindow):
def __init__(self, parent=None):
super(First, self).__init__(parent)
self.grid = QtGui.QGridLayout(self)
self.setGeometry(350, 200, 1000, 700)
self.widget = QtGui.QWidget()
Button1 = QtGui.QPushButton('...', self)
Button1.clicked.connect(self.on_pushButton_clicked)
self.grid.addWidget(Button1, 0, 0, 1, 1)
def on_pushButton_clicked(self):
self.Second = Second()
self.Second.setWindowTitle('Window')
self.Second.show()
def main():
app = QtGui.QApplication(sys.argv)
main = First()
main.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
When I click the button, I want to be able to finish up my action in the second window before continuing on the first. Right now, I can exit out of my first window and the second window remains open. How do you keep on the second window but keep the first window unselectable?
There are 2 possible solutions:
- Second must inherit from QDialog, pass it as parent to the first window and use exec_() instead of show:
class Second(QtGui.QDialog):
def __init__(self, parent=None):
super(Second, self).__init__(parent)
class First(QtGui.QMainWindow):
def __init__(self, parent=None):
super(First, self).__init__(parent)
self.setGeometry(350, 200, 1000, 700)
self.widget = QtGui.QWidget()
self.setCentralWidget(self.widget)
grid = QtGui.QGridLayout(self.widget)
Button1 = QtGui.QPushButton('...', self)
Button1.clicked.connect(self.on_pushButton_clicked)
grid.addWidget(Button1, 0, 0, 1, 1)
#QtCore.pyqtSlot()
def on_pushButton_clicked(self):
self.Second = Second(self)
self.Second.setWindowTitle('Window')
self.Second.exec_()
- Change the windowModality to Qt::WindowModal, activate the flag Qt::Dialog and pass it the first window as parent.
class Second(QtGui.QWidget):
def __init__(self, parent=None):
super(Second, self).__init__(parent)
self.setWindowModality(QtCore.Qt.WindowModal)
self.setWindowFlags(self.windowFlags() | QtCore.Qt.Dialog)
class First(QtGui.QMainWindow):
def __init__(self, parent=None):
super(First, self).__init__(parent)
self.setGeometry(350, 200, 1000, 700)
self.widget = QtGui.QWidget()
self.setCentralWidget(self.widget)
grid = QtGui.QGridLayout(self.widget)
Button1 = QtGui.QPushButton('...', self)
Button1.clicked.connect(self.on_pushButton_clicked)
grid.addWidget(Button1, 0, 0, 1, 1)
#QtCore.pyqtSlot()
def on_pushButton_clicked(self):
self.Second = Second(self)
self.Second.setWindowTitle('Window')
self.Second.show()

How to update QWidget's content?

There is a QWidget, which is called with the button "Start" in the main widget.
It shows some text, which should be updated every minute during the work of the QWidget.
How can I make this infinity updating within this code?
class ExampleWidget(QWidget):
def __init__(self, parent=None):
super().__init__()
self.setWindowTitle('Example Widget ScrollArea')
self.initUi()
def initUi(self):
area = QScrollArea(self)
area.setWidgetResizable(True)
self.scrollAreaWidgetContents = QLabel(some_text, self)
area.setWidget(self.scrollAreaWidgetContents)
button = QPushButton("Close")
button.clicked.connect(self.goMainWindow)
layoutV = QVBoxLayout()
layoutV.addWidget(area)
layoutV.addWidget(button)
self.setLayout(layoutV)
def goMainWindow(self):
self.hide()
def sizeHint(self):
return QSize(400, 200)
class MainWindow(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
start_main_button = QPushButton('Start', self)
start_main_button.move(40, 40)
start_main_button.clicked.connect(self.start)
self.setGeometry(300, 300, 290, 150)
self.setWindowTitle('Test')
def start(self):
global some_text
some_text = 'some text'
self.result_widget = ExampleWidget()
self.result_widget.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())
One of my tries:
def start(self):
global some_text
some_text = 'some text'
self.result_widget = ExampleWidget()
self.result_widget.show()
i = 0
while True:
i+=1
some_text+=str(i)
self.result_widget = ExampleWidget()
self.result_widget.show()
Forget the global variables because they are considered bad practice, on the other hand in a GUI you should avoid having loops that consume a lot of time, and in your case a while True blocks the GUI. In Qt if you want to do periodic tasks you must use a QTimer:
from PyQt5 import QtCore, QtWidgets
class ExampleWidget(QtWidgets.QWidget):
def __init__(self, parent=None):
super().__init__()
self.setWindowTitle('Example Widget ScrollArea')
self.initUi()
def initUi(self):
area = QtWidgets.QScrollArea()
area.setWidgetResizable(True)
self.scrollAreaWidgetContents = QtWidgets.QLabel("some_text")
area.setWidget(self.scrollAreaWidgetContents)
button = QtWidgets.QPushButton("Close")
button.clicked.connect(self.hide)
layoutV = QtWidgets.QVBoxLayout(self)
layoutV.addWidget(area)
layoutV.addWidget(button)
def update_text(self, text):
# update the text
self.scrollAreaWidgetContents.setText(text)
def sizeHint(self):
return QtCore.QSize(400, 200)
class MainWindow(QtWidgets.QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
start_main_button = QtWidgets.QPushButton('Start', self)
start_main_button.move(40, 40)
start_main_button.clicked.connect(self.start)
self.setGeometry(300, 300, 290, 150)
self.setWindowTitle('Test')
self.result_widget = ExampleWidget()
self.timer = QtCore.QTimer(self, interval=60*1000)
self.timer.timeout.connect(self.on_timeout)
self.counter = 0
self.initial_text = "some_text"
def on_timeout(self):
# this method will be called every 60 * 1000 ms
self.initial_text += str(self.counter)
self.result_widget.update_text(self.initial_text)
self.counter += 1
#QtCore.pyqtSlot()
def start(self):
self.result_widget.show()
# start timer
self.timer.start()
if __name__ == '__main__':
import sys
app = QtWidgets.QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())

PyQt: setCentralWidget clashes with QPushButton function

So I deduced down to this problem from my project that the setCentralWidget from the Slides Widget class I injected in the Main Window class causes the function of the buttons (i.e. opening a new Widget window) from the Main Window to not work at all.
If I remove the setCentralWidget the buttons work fine so without compromising any of the functions, what approach should I use for this? Should I use a different form of calling the Slides Widget class?
Any help would be appreciated, as always! Thanks!
from PyQt4 import QtCore, QtGui
import sys
from functools import partial
class MainWindow(QtGui.QMainWindow):
def __init__(self, image_files, parent=None):
super(MainWindow, self).__init__()
self.setupUi(self)
self.slides_widget = Slides(image_files, self)
#If you enable this down below, pushButton will not function
#and instead the slideshow will pop up and function correctly
#self.setCentralWidget(self.slides_widget)
def setupUi(self, MainWindow):
MainWindow.resize(1278, 688)
#MainWindow.setStyleSheet(self.styledata)
self.groupBox = QtGui.QGroupBox(MainWindow)
self.groupBox.setGeometry(QtCore.QRect(490, 220, 120, 371))
self.groupBox.setAlignment(QtCore.Qt.AlignHCenter|QtCore.Qt.AlignTop)
self.groupBox.setFlat(False)
self.groupBox.setCheckable(False)
self.pushButton_Desc = QtGui.QPushButton(self.groupBox)
self.pushButton_Desc.setGeometry(QtCore.QRect(20, 30, 71, 61))
self.pushButton_Desc.clicked.connect(partial(self.DescWindow))
self.groupBox.raise_()
self.NewWindow = QtGui.QWidget()
def DescWindow(self):
self.NewWindow.show();
class Slides(QtGui.QWidget):
def __init__(self, image_files, parent=None):
super(Slides, self).__init__(parent)
self.image_files = image_files
self.label = QtGui.QLabel("", self)
self.label.setGeometry(65, 225, 423, 363)
#buttons to rewind and forward
self.button = QtGui.QPushButton(". . .", self)
self.button.setGeometry(200, 100, 140, 30)
self.button.clicked.connect(self.timerEvent)
self.timer = QtCore.QBasicTimer()
self.step = 0
self.delay = 3000 #ms
def timerEvent(self, e=None):
if self.step >= len(self.image_files):
self.timer.start(self.delay, self)
self.step = 0
return
self.timer.start(self.delay, self)
file = self.image_files[self.step]
image = QtGui.QPixmap(file)
self.label.setPixmap(image)
#self.setWindowTitle("{} --> {}".format(str(self.step), file))
self.step += 1
image_files = ["images\slide1.jpg", "images\slide2.jpg", "images\slide3.jpg",
"images\slide4.jpg", "images\slide5.jpg"]
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
Form = MainWindow(image_files)
Form.show()
sys.exit(app.exec_())
The problem arises because first place the button and on this is placed the CentralWidget, the solution is to place the button in the CentralWidget, ie in Slides.
You must change:
def __init__(self, image_files, parent=None):
super(MainWindow, self).__init__()
self.setupUi(self)
self.slides_widget = Slides(image_files, self)
to:
def __init__(self, image_files, parent=None):
super(MainWindow, self).__init__()
self.slides_widget = Slides(image_files, self)
self.setupUi(self)
and
self.groupBox = QtGui.QGroupBox(MainWindow)
to:
self.groupBox = QtGui.QGroupBox(MainWindow.slides_widget)
Complete code:
from PyQt4 import QtCore, QtGui
import sys
class MainWindow(QtGui.QMainWindow):
def __init__(self, image_files, parent=None):
super(MainWindow, self).__init__()
self.slides_widget = Slides(image_files, self)
self.setupUi(self)
def setupUi(self, MainWindow):
MainWindow.resize(1278, 688)
#MainWindow.setStyleSheet(self.styledata)
self.groupBox = QtGui.QGroupBox(MainWindow.slides_widget)
self.groupBox.setGeometry(QtCore.QRect(490, 220, 120, 371))
self.groupBox.setAlignment(QtCore.Qt.AlignHCenter|QtCore.Qt.AlignTop)
self.groupBox.setFlat(False)
self.groupBox.setCheckable(False)
self.pushButton_Desc = QtGui.QPushButton(self.groupBox)
self.pushButton_Desc.setGeometry(QtCore.QRect(20, 30, 71, 61))
self.pushButton_Desc.clicked.connect(self.DescWindow)
self.setCentralWidget(self.slides_widget)
self.groupBox.raise_()
self.NewWindow = QtGui.QWidget()
def DescWindow(self):
self.NewWindow.show();
class Slides(QtGui.QWidget):
def __init__(self, image_files, parent=None):
super(Slides, self).__init__(parent)
self.image_files = image_files
self.label = QtGui.QLabel("", self)
self.label.setGeometry(65, 225, 423, 363)
#buttons to rewind and forward
self.button = QtGui.QPushButton(". . .", self)
self.button.setGeometry(200, 100, 140, 30)
self.button.clicked.connect(self.timerEvent)
self.timer = QtCore.QBasicTimer()
self.step = 0
self.delay = 3000 #ms
def timerEvent(self, e=None):
if self.step >= len(self.image_files):
self.timer.start(self.delay, self)
self.step = 0
return
self.timer.start(self.delay, self)
file = self.image_files[self.step]
image = QtGui.QPixmap(file)
self.label.setPixmap(image)
#self.setWindowTitle("{} --> {}".format(str(self.step), file))
self.step += 1
image_files = ["images\slide1.jpg", "images\slide2.jpg", "images\slide3.jpg",
"images\slide4.jpg", "images\slide5.jpg"]
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
Form = MainWindow(image_files)
Form.show()
sys.exit(app.exec_())

Updating pyqt widget content from another widget

Moving on from my last question, I'm stuck once again. I'm trying to update content of parent widget from child widget. The code seems to work first time but after closing and re-opening the form widget it does not update the parent widget.
Following is the code.
from PyQt4 import QtGui, QtCore
from functools import partial
import sys
class MainWidget(QtGui.QWidget):
def __init__(self):
super(MainWidget, self).__init__()
self.main_widget()
def main_widget(self):
self.form = Form()
self.simple = Simple()
grid = QtGui.QGridLayout()
self.last_input_label = QtGui.QLabel("")
grid.addWidget(self.last_input_label, 1, 0, 3, 1)
show_form_button = QtGui.QPushButton("Show Form")
show_form_button.clicked.connect(partial(self.form.show_form, self.last_input_label))
grid.addWidget(show_form_button, 0, 0)
show_simple_button = QtGui.QPushButton("Show Simple")
show_simple_button.clicked.connect(self.simple.show_simple)
grid.addWidget(show_simple_button, 0, 1)
another_button = QtGui.QPushButton("Print Hello")
another_button.clicked.connect(partial(print, "Hello"))
grid.addWidget(another_button, 0, 2)
self.setLayout(grid)
self.setWindowTitle("Main Widget")
self.show()
def closeEvent(self, QCloseEvent):
QtGui.QApplication.closeAllWindows()
class Form(QtGui.QWidget):
def __init__(self):
print("form initialized")
super(Form, self).__init__()
def show_form(self, last_input_label):
print("form called")
grid = QtGui.QGridLayout()
self.last_input_label = last_input_label
label = QtGui.QLabel("Name")
grid.addWidget(label, 0, 0)
self.line_edit = QtGui.QLineEdit()
grid.addWidget(self.line_edit, 0, 1)
self.submit_button = QtGui.QPushButton("Submit")
self.submit_button.clicked.connect(self.print_form_data)
grid.addWidget(self.submit_button, 1, 1)
self.setLayout(grid)
self.setGeometry(250, 300, 250, 150)
self.setWindowTitle("Form Widget")
self.show()
def get_form_data(self):
form_data = {
"name": self.line_edit.text()
}
return form_data
def print_form_data(self):
self.x = self.get_form_data()
for item in self.x:
print(item + ": " + self.x[item])
self.last_input_label.setText(self.x[item])
return
class Simple(QtGui.QDialog):
def __init__(self):
print("simple initialized")
super(Simple, self).__init__()
def show_simple(self):
print("simple called")
self.setGeometry(300, 250, 250, 150)
self.setWindowTitle("Simple Widget")
self.show()
def main():
app = QtGui.QApplication(sys.argv)
main_widget = MainWidget()
sys.exit(app.exec_())
if __name__ == "__main__":
main()
Please Help!
You're calling the initialization code each time you show the widget. Move all that into the __init__ method where it belongs and it all works.
Move everything beside this into the init method. I can't say exactly why running the init code more would break the connection. But somehow it does. Maybe someone else can fill in that detail.
def show_form(self, last_input_label):
print("form called")
self.last_input_label = last_input_label
self.show()

PyQt class inheritance

I am having troubles to understand class inheritance with Python/PyQt. I have a MainWindow and a Popup QWidget. I want to interact with the self.label1 of the MainWindow after the QWidget was opened in a pop up window but I don't know how to do it. I know only the other way around, to reach all widgets from the popup Window inside MainWindow but not vice versa.
Here is an example, self.label1 of MainWindow should get another text after MyPopup opens in a new window:
import sys
from PyQt4.Qt import *
class MyPopup(QWidget):
def __init__(self):
QWidget.__init__(self)
# I want to change the lable1 of MainWindow
self.cw.label1.setText('hello')
class MainWindow(QMainWindow):
def __init__(self, *args):
QMainWindow.__init__(self, *args)
self.cw = QWidget(self)
self.setCentralWidget(self.cw)
self.btn1 = QPushButton("Click me", self.cw)
self.btn1.setGeometry(QRect(50, 50, 100, 30))
self.label1 = QLabel("No Commands running", self.cw)
self.connect(self.btn1, SIGNAL("clicked()"), self.doit)
self.w = None
def doit(self):
self.w = MyPopup()
self.w.setGeometry(QRect(100, 100, 400, 200))
self.w.show()
if __name__ == "__main__":
app = QApplication(sys.argv)
myapp = MainWindow()
myapp.show()
sys.exit(app.exec_())
You need to pass the main window as a parameter to the constructor of MyPopup, try this:
import sys
from PyQt4.Qt import *
class MyPopup(QWidget):
def __init__(self, mainWindow):
QWidget.__init__(self)
# use the mainWindow passed as parameter
mainWindow.label1.setText('hello')
class MainWindow(QMainWindow):
def __init__(self, *args):
QMainWindow.__init__(self, *args)
self.cw = QWidget(self)
self.setCentralWidget(self.cw)
self.btn1 = QPushButton("Click me", self.cw)
self.btn1.setGeometry(QRect(50, 50, 100, 30))
self.label1 = QLabel("No Commands running", self.cw)
self.connect(self.btn1, SIGNAL("clicked()"), self.doit)
self.w = None
def doit(self):
self.w = MyPopup(self) #when creating the popup pass in the main window
self.w.setGeometry(QRect(100, 100, 400, 200))
self.w.show()
if __name__ == "__main__":
app = QApplication(sys.argv)
myapp = MainWindow()
myapp.show()
sys.exit(app.exec_())
This is the prior answer from Alvaro Fuentes, with the minor updates necessary for PyQt5.
import sys
from PyQt5.Qt import *
class MyPopup(QWidget):
def __init__(self, mainwin):
QWidget.__init__(self)
# I want to change the lable1 of MainWindow
mainwin.label1.setText('hello')
class MainWindow(QMainWindow):
def __init__(self, *args):
QMainWindow.__init__(self, *args)
self.cw = QWidget(self)
self.setCentralWidget(self.cw)
self.btn1 = QPushButton("Click me", self.cw)
self.btn1.setGeometry(QRect(50, 50, 100, 30))
self.label1 = QLabel("No Commands running", self.cw)
self.btn1.clicked.connect(self.doit)
self.w = None
def doit(self):
self.w = MyPopup(self)
self.w.setGeometry(QRect(100, 100, 400, 200))
self.w.show()
if __name__ == "__main__":
app = QApplication(sys.argv)
myapp = MainWindow()
myapp.show()
sys.exit(app.exec_())

Categories