Skip to content

Instantly share code, notes, and snippets.

@Holi0317
Created May 5, 2018 08:34
Show Gist options
  • Save Holi0317/cacd4c58643151142992a76ebccf5bc8 to your computer and use it in GitHub Desktop.
Save Holi0317/cacd4c58643151142992a76ebccf5bc8 to your computer and use it in GitHub Desktop.
Demo of popup windows using PySide2
"""
Popup windows for PySide2
"""
import sys
import threading
import time
from PySide2.QtCore import QThread
from PySide2.QtWidgets import QApplication, QMessageBox
class Sleeper(QThread):
def run(self):
time.sleep(2)
msg = make_message()
msg.show()
time.sleep(4)
msg.hide()
def make_message():
msg = QMessageBox()
msg.setIcon(QMessageBox.Warning)
msg.setText("Here is example text")
msg.setInformativeText("Informative text here!")
msg.setStandardButtons(QMessageBox.Ok)
return msg
class App(QApplication):
def __init__(self):
QApplication.__init__(self, [])
self.t = Sleeper()
self.t.start()
def main():
"""Entry of the script."""
app = App()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
@GreatV
Copy link

GreatV commented Dec 18, 2018

Not work for me.

QObject: Cannot create children for a parent that is in a different thread.
(Parent is App(0x10b7280), parent's thread is QThread(0xd4d380), current thread is Sleeper(0x11d87a0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment