Answer the question
In order to leave comments, you need to log in
How to make another non-moving button here?
It is necessary here to make a button in the lower left corner of the screen (static), and already existing in the right corner (running).
In the picture , D is moving, and C is static
import sys
import random
from PyQt5.QtWidgets import QWidget, QApplication, QPushButton
from PyQt5.QtCore import pyqtSignal
from tkinter import *
from subprocess import call
class Button(QPushButton):
mouseMoved = pyqtSignal()
def mouseMoveEvent(self, event):
self.mouseMoved.emit()
class Example(QWidget):
def __init__(self):
super().__init__()
self.coords = [140, 160]
self.btn_size = [120, 40]
self.d = 15
self.w = 500
self.h = 400
self.setGeometry(300, 300, self.w, self.h)
self.setWindowTitle('Опрос')
self.btn = Button(self)
self.btn.setMouseTracking(True);
self.btn.setText("Да")
self.btn.resize(*self.btn_size)
self.btn.move(*self.coords)
self.btn.mouseMoved.connect(self.moveButton)
self.show()
def moveButton(self):
self.coords[0] = random.randint(0, self.w - self.btn_size[0])
self.coords[1] = random.randint(0, self.h - self.btn_size[1])
self.btn.move(*self.coords)
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
ex.show()
sys.exit(app.exec_())
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question