QWidget 没有属性 setWindowTitle

QWidget has not attribute setWinowTitle

import sys 

from PyQt4.QtGui import * 

app = QApplication(sys.argv)

w = QWidget()
w.resize(250,150)
w.move(300,300)
w.setWinowTitle(('hey'))
w.show()


sys.exit(a.exec_())

Traceback (most recent call last): File "gu.py", line 9, in w.setWinowTitle(('hey')) AttributeError: 'QWidget' object has no attribute 'setWinowTitle'

我正在使用 Windows 并使用 t 二进制安装程序安装了 pyqt。

以正确的方式做:)

import sys
from PyQt4 import QtGui

class ExampleWidget(QtGui.QWidget):

    def __init__(self):
        super(ExampleWidget, self).__init__()
        self.setWindowTitle('Hey')
        self.show()

def main():
    qtApp = QtGui.QApplication(sys.argv)
    wid = ExampleWidget()
    sys.exit(qtApp.exec_())

if __name__ == '__main__':
    main()

并避免使用*导入,这不是好的做法

这里是您代码的工作版本。

import sys 
from PyQt4.QtGui import * 

app = QApplication(sys.argv)

w = QWidget()
w.resize(250,150)
w.move(300,300)
w.setWindowTitle(('hey'))
w.show()
sys.exit(app.exec_())

你打错了 setWindowTitle 而不是 setWinowTitle :) 并且你将 QApplication 声明为应用程序并且你是 exec 的。