Issue
I’ve been trying to make an object move between three locations upon clicking a button. This is the code that I have now
def objectMove():
If window.button.pressed():
window.object1.setGeometry(200,120,91,91)
window.object1.setGeometry(1,120,91,91)
window.object1.setGeometry(90,120,91,91)
window.button.clicked.connect(objectMove)
My intention for this code was to have an object move to these three locations every time the button is clicked and the button can only be clicked 9 times before the screen times out. But I’m unsure how I could fix this
Solution
hold qrects of positions in dict under self_def_init_
self.val = 0
self.val_dict = {0:QRect(200,120,91,91),1:QRect(200,120,91,91),2:QRect(200,120,91,91)}
and update your method as below code
def objectMove():
windowObject.setGeometry(self.val_dict[self.val])
self.val += 1
if self.val == 3:
self.val = 0
Answered By - SimoN SavioR
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.