I have a pygame code that rotates the image I need around my axis.

while True: pygame.event.pump() event_handler() if i == 0: prize, needed_angle, angle, deg_count, a = randomize() print(prize) i += 1 if angle >= needed_angle: DSP.fill(backgr) pygame.display.update() i = event_handler() pass elif angle < needed_angle: DSP.fill(backgr) deg_count += a angle += a image_new = pygame.transform.rotozoom(image, angle, 1) image1_new = image_new.get_rect() image1_new.center = (400,400) if (needed_angle - deg_count) <= 495: if (a - 0.0361) > 0: a -= 0.0361 else: pass else: pass DSP.blit(image1, (100,100)) DSP.blit(image_new, image1_new) pygame.display.update() 

It looks like this: https://www.youtube.com/watch?v=eQxdYb_iKU4

However, if the window loses focus, the code stops working. As I understand it, this is not fixed at all (I need everything to work without focus).

Therefore, I am looking for analogues, but I can not find a suitable one.

Please tell me if there is such a possibility in PyQt or OpenCV, or am I looking at all in the wrong place?

Thank you in advance.

  • one
    As far as I know PyGame itself does not require focus to update the window. As I understand it, your application is simply written so that it only works with focus. - Alex Krass
  • PyQt has qml. he lets you do anything - Mr Morgan

1 answer 1

PyQt5, try:

 from PyQt5.QtCore import Qt, QTimer from PyQt5.QtGui import QPixmap, QPainter, QImage from PyQt5.QtWidgets import QWidget, QLabel, QApplication, QVBoxLayout class Window(QWidget): def __init__(self, *args, **kwargs): super(Window, self).__init__(*args, **kwargs) self.imageLabel = QLabel(self) self.imageLabel.setAlignment(Qt.AlignCenter) layout = QVBoxLayout(self) layout.addWidget(self.imageLabel) # Π˜ΡΡ…ΠΎΠ΄Π½ΠΎΠ΅ ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅ self.srcImage = QImage('fg.png') self.imageLabel.setPixmap(QPixmap.fromImage(self.srcImage).scaled(250, 250)) self.timer = QTimer(interval=500) self.timer.timeout.connect(self.doAnticlockwise) self.timer.start() def doAnticlockwise(self): # ΠΏΡ€ΠΎΡ‚ΠΈΠ² часовой стрСлки 45 градусов image = QImage(self.srcImage.size(), QImage.Format_ARGB32_Premultiplied) painter = QPainter() painter.begin(image) # Π’ΠΎΠ·ΡŒΠΌΠΈΡ‚Π΅ Ρ†Π΅Π½Ρ‚Ρ€ изобраТСния ΠΊΠ°ΠΊ источник hw = self.srcImage.width() / 2 hh = self.srcImage.height() / 2 painter.translate(hw, hh) painter.rotate(-45) # Π’Ρ€Π°Ρ‰Π΅Π½ΠΈΠ΅ -45 градусов painter.drawImage(-hw, -hh, self.srcImage) # ΠžΡ„ΠΎΡ€ΠΌΠΈ ΠΊΠ°Ρ€Ρ‚ΠΈΠ½Ρƒ painter.end() self.srcImage = image # Π—Π°ΠΌΠ΅Π½ΠΈΡ‚ΡŒ self.imageLabel.setPixmap(QPixmap.fromImage(self.srcImage).scaled(250, 250)) if __name__ == '__main__': import sys app = QApplication(sys.argv) w = Window() w.show() sys.exit(app.exec_()) 

enter image description here

enter image description here