Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.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 PyQt5标签设置异常行为_Python_Macos_Pyqt_Pyqt5 - Fatal编程技术网

Python PyQt5标签设置异常行为

Python PyQt5标签设置异常行为,python,macos,pyqt,pyqt5,Python,Macos,Pyqt,Pyqt5,我是Python和PyQt5的新手。现在开始学习,但是我发现在运行代码时有一种奇怪的行为。下面是我的开发环境 操作系统:MacOS Python版本:Python 3.8 Qt版本:PyQt5 IDE:mac的VS代码 无论是使用VS代码调试器功能还是直接在终端中运行脚本。当我单击该按钮时,文本将不会更新,直到我将焦点从主窗口更改出来并将其调回。有没有任何迹象表明为什么会发生这种情况?感谢您的帮助在终端中运行时会发生同样的情况吗?我认为这是一个bug,我不知道是PyQt还是Qt,你使用的是什

我是Python和PyQt5的新手。现在开始学习,但是我发现在运行代码时有一种奇怪的行为。下面是我的开发环境

  • 操作系统:MacOS
  • Python版本:Python 3.8
  • Qt版本:PyQt5
  • IDE:mac的VS代码

无论是使用VS代码调试器功能还是直接在终端中运行脚本。当我单击该按钮时,文本将不会更新,直到我将焦点从主窗口更改出来并将其调回。有没有任何迹象表明为什么会发生这种情况?感谢您的帮助

在终端中运行时会发生同样的情况吗?我认为这是一个bug,我不知道是PyQt还是Qt,你使用的是什么版本的PyQt5?我认为是5.13.2这是一个简短的电影链接:嗯,这可能是一个Qt bug,可能是由某些MacOs驱动程序引起的,因为你的逻辑是正确的。报告:谢谢你的帮助
import sys
from PyQt5.QtWidgets import *


class Window(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("Using Labels")
        self.setGeometry(50, 50, 350, 350)
        self.UI()

    def UI(self):
        self.text = QLabel("My Text", self)
        enterbutton = QPushButton("Enter", self)
        exitbutton = QPushButton("Exit", self)
        self.text.move(160, 50)
        enterbutton.move(100, 80)
        exitbutton.move(200, 80)
        enterbutton.clicked.connect(self.enterFunc)
        exitbutton.clicked.connect(self.exitFunc)
        self.show()

    def enterFunc(self):
        self.text.setText("You Click Enter")
        self.text.resize(150, 20)

    def exitFunc(self):
        self.text.setText("You Click Exit")
        self.text.resize(150, 20)


def main():
    App = QApplication(sys.argv)
    window = Window()
    sys.exit(App.exec_())

if __name__ == '__main__':
    main()