Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 调用hide()时如何使标签完全隐藏?_Python_Pyqt5 - Fatal编程技术网

Python 调用hide()时如何使标签完全隐藏?

Python 调用hide()时如何使标签完全隐藏?,python,pyqt5,Python,Pyqt5,我如何让标签和盒子完全隐藏而不只是一半 隐藏小部件 非隐藏小部件 import sys from PyQt5.QtWidgets import * from PyQt5.QtCore import * class App(QWidget): def __init__(self): super().__init__() self.title = 'Code' self.left = 1400 self.top = 500

我如何让标签和盒子完全隐藏而不只是一半

隐藏小部件

非隐藏小部件

import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *

class App(QWidget):
    def __init__(self):
        super().__init__()
        self.title = 'Code'
        self.left = 1400
        self.top = 500
        self.width = 400
        self.height = 168
        self.initUI()
        self.count = 0

    def initUI(self):
        self.button = QPushButton('button', self)
        self.button.move(7,42)
        self.button.clicked.connect(self.test)

        self.box = QLineEdit(self)
        self.box.setGeometry(5,19,20,20)
        self.box.setAlignment(Qt.AlignRight)
        self.box.hide()

        self.l = QLabel(self)
        self.l.setText('Letters:')
        self.l.move(26,20)
        self.l.hide()

        self.setWindowTitle(self.title)
        self.setGeometry(self.left, self.top, self.width, self.height)
        self.show()

    def test(self):
        if self.count % 2 == 0:
            self.box.show()
            self.l.show()
        elif self.count % 2 == 1:
            self.l.hide()
            self.box.hide()
        self.count += 1
        print('Box: ', self.box.isVisible())
        print('Label: ', self.l.isVisible())
        print()

if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = App()
    sys.exit(app.exec_())


我试图在第一次单击时获取标签并显示,然后在第二次单击时隐藏,但第一次单击时显示,但第二次单击时隐藏了一半if。

我没有注意到您指出的问题,您可以显示问题的图像。您使用的是什么版本的pyqt5?我建议使用最新版本5.12.1。IMHO是一个只影响MacOS的错误,在Linux中它工作正常。我使用的是PyQt5-5.12.1我建议您报告该错误:我从未见过您描述的行为,我无法在Linux上复制它。顺便说一句:与其手动设置几何图形并在特定位置移动小部件,不如使用
QVBoxLayout
例如。。。将为您节省大量时间和头痛如果您没有观察到您指出的问题,您可以显示问题的图像您使用的是什么版本的pyqt5?我建议使用最新版本5.12.1。IMHO是一个只影响MacOS的错误,在Linux中它工作正常。我使用的是PyQt5-5.12.1我建议您报告该错误:我从未见过您描述的行为,我无法在Linux上复制它。顺便说一句:与其手动设置几何图形并在特定位置移动小部件,不如使用
QVBoxLayout
例如。。。将为您节省大量时间和头痛