Aaron Henderson Aaron Henderson - 1 month ago 9x
Python Question

How can I self hide and show QDialog() in PyQT5?

I have a GUI that was generated using Qt Designer, I used pyuic5 to generate a .py file. In a separate py (program.py) file I import my UI a do all my work there.


import sys, os, time
from subprocess import call
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyCred_GUI import Ui_Dialog

class MyGUI(Ui_Dialog):
def __init__(self, dialog):


def cancelbutton(self):

if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
dialog = QtWidgets.QDialog()
prog = MyGUI(dialog)


I pulled a lot out just to focus on the issue here. When I click my Cancel button, I want the window to hide, set a timer, and then reappear after so many seconds. I have tried every combination of self.close() self.hide() self.destroy() and none of them hide my window. I get an error that says

"AttributeError: 'MyGUI' object has no attribute 'hide'"

Which makes sense because MyGUI doesn't have a hide() function. I am at a complete loss on how to hide this window.

EDIT (Solved)
For future people, as suggested by Hi Im Frogatto dialog.hide() worked.


In your code snippet, dialog is of type QDialog and thereby having hide method. However instances of MyGUI class seem to not have such a method. So, if you write dialog.hide() in that __init__() function, you can hide it.