Advertisement
robertvari

Image background

Apr 5th, 2021
753
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.89 KB | None | 0 0
  1. from PySide2.QtWidgets import QWidget, QVBoxLayout, QPushButton, QApplication
  2. from PySide2.QtGui import QPainter, QImage
  3. import sys
  4.  
  5.  
  6. IMAGE_PATH = r"e:\Photos\Austria wekend\IMG_7259.JPG"
  7.  
  8.  
  9. class GameWindowDialog(QWidget):
  10.     def __init__(self):
  11.         super(GameWindowDialog, self).__init__()
  12.         self.resize(500, 500)
  13.         self.background_image = QImage(IMAGE_PATH)
  14.  
  15.         main_layout = QVBoxLayout(self)
  16.         button = QPushButton("Click")
  17.         main_layout.addWidget(button)
  18.  
  19.     def paintEvent(self, e):
  20.         painter = QPainter()
  21.         painter.begin(self)
  22.         self.drawWidget(painter)
  23.         painter.end()
  24.  
  25.     def drawWidget(self, painter):
  26.         rect = self.rect()
  27.         painter.drawImage(rect, self.background_image)
  28.  
  29.  
  30. if __name__ == '__main__':
  31.     app = QApplication(sys.argv)
  32.     win = GameWindowDialog()
  33.     win.show()
  34.     app.exec_()
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement