我正在使用一个函数将我的应用程序设置在屏幕中央,但它给我错误 'builtin_function_or_method' object has no attribute 'center'
I am using a function to set my app at centre of the screen but it is giving me error 'builtin_function_or_method' object has no attribute 'center'
显示:'builtin_function_or_method' 对象没有属性 'center'。
代码在这里:
def setCenter(self): ///this function not working
'''Function to align the application at centre'''
qRect=self.frameGeometry()
centerPoint=QDesktopWidget().availableGeometry.center()
qRect.moveCenter(centerPoint)
self.move(qRect.topLeft())
此外,我已将我的应用程序 window 命名为 mywindow
,因此我在 main()
中将此函数称为 mywindow.setCenter()
。
我做对了吗?
QDesktopWidget.availableGeometry
是一个函数。因此它没有 center
的属性。您需要像 availableGeometry()
这样调用该函数。返回的 QRect
具有您可以调用的 center
属性。
对于默认屏幕的几何形状,只需使用:
QDesktopWidget().availableGeometry().center()
显示:'builtin_function_or_method' 对象没有属性 'center'。 代码在这里:
def setCenter(self): ///this function not working
'''Function to align the application at centre'''
qRect=self.frameGeometry()
centerPoint=QDesktopWidget().availableGeometry.center()
qRect.moveCenter(centerPoint)
self.move(qRect.topLeft())
此外,我已将我的应用程序 window 命名为 mywindow
,因此我在 main()
中将此函数称为 mywindow.setCenter()
。
我做对了吗?
QDesktopWidget.availableGeometry
是一个函数。因此它没有 center
的属性。您需要像 availableGeometry()
这样调用该函数。返回的 QRect
具有您可以调用的 center
属性。
对于默认屏幕的几何形状,只需使用:
QDesktopWidget().availableGeometry().center()