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
• 14,970 points
14 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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,120 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
16 views
0 votes
1 answer

Is there a foreach function in python and is there a way to implement it if there isnt any

Every occurence of "foreach" I've seen (PHP, ...READ MORE

answered Aug 31, 2018 in Python by charlie_brown
• 7,710 points
43 views
0 votes
1 answer

How does Python know whether a variable in the class is a method or a variable?

In python objects/variables are wrapped into methods ...READ MORE

answered Sep 18, 2018 in Python by ariaholic
• 7,320 points
20 views
0 votes
1 answer

how can i count the items in a list?

suppose you have a list a = [0,1,2,3,4,5,6,7,8,9,10] now ...READ MORE

answered May 2 in Python by Mohammad
• 1,400 points
24 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,120 points
49 views
0 votes
2 answers

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

  Tuple is a collection of Python objects.it is ...READ MORE

answered Apr 12 in Python by rajesh
• 1,210 points
50 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.