0
我想为光标移动创建一个应用程序,如果用户输入任何数字,比如说5 &选择一个形状(圆形或方形):然后鼠标光标必须旋转5次使选定的形状。如何在PyQt4中以圆形旋转鼠标
我得到错误:
cursor.setPos((pos[0] + 1, pos[1] + 1))
TypeError: 'QPoint' object does not support indexing.
这是我的代码:
import sys
from PyQt4 import QtGui, QtCore
class Example(QtGui.QWidget):
def __init__(self):
super(Example, self).__init__()
self.initUI()
def initUI(self):
lblText = QtGui.QLabel("Enter Number: ", self)
numText = QtGui.QLineEdit(self)
btncir = QtGui.QPushButton('Circle', self)
btncir.setToolTip('Press this button to rotate mouse in circle')
btnsqr = QtGui.QPushButton('Square', self)
btnsqr.setToolTip('Press this button to rotate mouse in square')
fbox = QtGui.QFormLayout()
fbox.addRow(lblText, numText)
fbox.addRow(btncir, btnsqr)
self.setLayout(fbox)
cursor = QtGui.QCursor()
pos = cursor.pos()
cursor.setPos((pos[0] + 1, pos[1] + 1))
self.setWindowTitle('Move Cursor')
self.show()
def main():
app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
感谢您的时间,但再次添加此它给我的错误.. 错误: cursor.setPos((pos.x + 100,+ pos.y 100)) 类型错误:不支持的操作数类型(S)为+:“builtin_function_or_method”和“INT” 我的主要目的是无论如何旋转圆周运动的光标。你能帮助我吗?感谢您的回复:) –
您收到错误是因为我犯了一个错误。 ''pos.x''返回方法,'pos.x()''的值。我做了一个编辑,为你写了一个小例子。 – alexblae
我试图运行由u ..所做的代码,它没有错误执行,但我没有得到任何输出。 我导入这些库以运行该代码: import numpy as np import time 我输入了正确的库吗? –