Hide a window in the constructor immediately after it is created?

0 votes

I want to hide a window immediately after it is created. It works only if I do this with the help of button or something.

class Example(QWidget):
    def __init__(self, parent=None):
        super(Example, self).__init__(parent)
        self.hide() # doesn't work
        self.btn = QPushButton('Hide', self)
        self.btn.clicked.connect(self.click) # works
        self.btn.show()

    def click(self): # works
        self.hide()

Sep 28, 2018 in Python by bug_seeker
• 15,360 points
28 views

1 answer to this question.

0 votes

Apparently it seems that the code should work. What may be happening is that you are calling show() after creating the object. For example:

example = Example()
example.show()

Read this answer about hide() and show(): What's the difference in Qt between setVisible, setShown and show/hide

answered Sep 28, 2018 by Priyaj
• 56,940 points

Related Questions In Python

0 votes
1 answer

How to hide a window in the constructor immediately after creation?

You can use QtCore.QTimer class Example(QWidget):     def __init__(self, app):         QWidget.__init__(self)         QTimer.singleShot(0, ...READ MORE

answered Apr 17, 2018 in Python by anonymous
41 views
0 votes
1 answer

Is it possible to run a function in Python using the command line?

Suppose your file name is demo.py and ...READ MORE

answered Jun 26 in Python by Neel
• 3,010 points
58 views
0 votes
1 answer

Is it possible to print all the modules imported in a python script?

Since I am using Python 3.6, I ...READ MORE

answered Jul 3 in Python by Neel
• 3,010 points
37 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 348 views
0 votes
1 answer

What is the meaning of “int(a[::-1])” in Python?

Assumming a is a string. The Slice ...READ MORE

answered Aug 27, 2018 in Python by Priyaj
• 56,940 points
84 views
0 votes
3 answers