Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
import os
import sys
from io import BytesIO
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout
from PyQt5.QtWidgets import QLabel, QPushButton, QMessageBox
from PyQt5.QtGui import QPixmap, QImage
import requests
url = """https://3.bp.blogspot.com/-rDqzMGTOAzI/U0Uj\
-HQauwI/AAAAAAAAB1c/4YfKMvqN_wk/s1600/%D0%94%D0%B0%D0\
%B2%D0%B0%D0%B9+%D1%8F+%D0%BF%D0%BE%D0%B8%D1%89%D1%83+\
%D0%B2+Google+%D0%B7%D0%B0+%D1%82%D0%B5%D0%B1%D1%8F.png
"""
# Отловить ошибки в слотах PyQt5
def log_uncaught_exceptions(ex_cls, ex, tb):
text = '{}: {}:\n'.format(ex_cls.__name__, ex)
import traceback
text += ''.join(traceback.format_tb(tb))
print(text)
QMessageBox.critical(None, 'Упс( Ошибочка...', text)
quit()
sys.excepthook = log_uncaught_exceptions
class WindowsApplication(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle('Супер приложение')
self.setGeometry(300, 200, 800, 600)
vbox = QVBoxLayout(self)
label = QLabel()
button = QPushButton(text='Сделать снимок приложения')
button.clicked.connect(self.buttonHandler)
vbox.addWidget(label)
vbox.addWidget(button)
content = requests.get(url).content
pixmap = QPixmap()
pixmap.loadFromData(content)
label.setPixmap(pixmap)
def buttonHandler(self):
grab = self.grab()
grab.save('image.png', 'png')
os.startfile('image.png')
print('END')
def main():
application = QApplication(sys.argv)
main_window = WindowsApplication()
main_window.show()
sys.exit(application.exec_())
if __name__ == '__main__':
main()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question