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,520 points
1,010 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
• 58,090 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
574 views
0 votes
1 answer
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, 2019 in Python by Neel
• 3,020 points
737 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, 2019 in Python by Neel
• 3,020 points
2,872 views
0 votes
2 answers
+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 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,058 views
0 votes
1 answer
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
• 58,090 points
6,130 views
0 votes
4 answers

What is a Tuple in Python and how to use it?

Tuples  are a  Unchanging sequence of values, ...READ MORE

answered Jun 21, 2020 in Python by sahil
• 580 points
1,400 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP