import os , sys , time
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
import numpy as np
def __init__(self):
super().__init__()
self.setWindowFlags(Qt.WindowStaysOnTopHint | Qt.FramelessWindowHint)
self.setAttribute(Qt.WA_TranslucentBackground)
self.initUI()
def initUI(self):
self.setGeometry(30, 30, 300, 300)
self.setWindowTitle('blRect')
self.show()
def screenshot(self):
self.
preview_screen = QApplication.
primaryScreen().
grabWindow(self.
winId() ) self.preview_screen.save('test.jpg', "jpg")
def paintEvent(self, e):
qp.begin(self)
self.draw_rect(qp)
self.screenshot()
qp.end()
def draw_rect(self, qp):
qp.
setBrush(QColor(255,
255,
0)) # print(self.width() , self.height())
for i in range(3):
rand_x = 100 * np.random.randn()
rand_y = 100 * np.random.randn()
qp.drawRect(self.width() /2 + rand_x, self.height() / 2 + rand_y, 100, 20)
def main():
ex = MyApp()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
import os , sys , time
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
import numpy as np
class MyApp(QWidget):
def __init__(self):
super().__init__()
self.setWindowFlags(Qt.WindowStaysOnTopHint | Qt.FramelessWindowHint)
self.setAttribute(Qt.WA_TranslucentBackground)
self.initUI()
def initUI(self):
self.setGeometry(30, 30, 300, 300)
self.setWindowTitle('blRect')
self.show()
def screenshot(self):
self.preview_screen = QApplication.primaryScreen().grabWindow(self.winId() )
self.preview_screen.save('test.jpg', "jpg")
def paintEvent(self, e):
qp = QPainter()
qp.begin(self)
self.draw_rect(qp)
self.screenshot()
qp.end()
def draw_rect(self, qp):
qp.setBrush(QColor(255, 255, 0))
qp.setPen(QPen(QColor(0, 0, 0), -1))
qp.setBrush(QColor(0, 0, 0))
# print(self.width() , self.height())
for i in range(3):
rand_x = 100 * np.random.randn()
rand_y = 100 * np.random.randn()
qp.drawRect(self.width() /2 + rand_x, self.height() / 2 + rand_y, 100, 20)
def main():
app = QApplication(sys.argv)
ex = MyApp()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
To copy to clipboard, switch view to plain text mode
Bookmarks