0

I have very limited knowledge of PyQt5 but was given a script that I'm having some problems altering. At startup the script is designed to show a frame upon which an image appears, together with a menubar.

The main part of the script at the bottom of the file is this:

def main():
    global window
    app = QApplication([])
    window = MainMenu()
    window.show()
    sys.exit(app.exec_())

if __name__ == '__main__':
    main()

MainMenu itself is a class, defined earlier, which starts out as follows:

class MainMenu(QMainWindow):
    def __init__(self):
        super(MainMenu, self).__init__()
        self.window()
        layout = self.frame_layout()
        self.create_menubar()
    
    def window(self):
        screen_width, screen_height = pyautogui.size() 
        self.setGeometry(0, 0, screen_width - 25, screen_height - 180) 
        self.showMaximized()        
        startup_background(self) 

...and so on.

startup_background in the last line above is a function that is designed to create the initial background using a specified .png file. I tried to create this function using the following in the startup_background function:

pixmap = QPixmap(background.png).scaled(window.width(), window.height(),QtCore.Qt.KeepAspectRatio)
palette = QPalette()
palette.setBrush(QPalette.Background, QBrush(pixmap))
window.setPalette(palette)

The problem is that the background image, which is a simple multiple time series plot, essentially appears more than once as shown by the ''chopped off'' right portion of the image below:

enter image description here

I also tried using a label by replacing the lines above with pallette with a label:

label = QLabel(window)
label.setPixmap(pixmap)

This produced nothing.

fishbacp
  • 1,123
  • 3
  • 14
  • 29
  • 1
    Setting a pixmap as a palette results in making that pixmap a *pattern*, similarly to setting the background on an HTML page, which shows the image tiled. Your attempt to use the label is also incorrect because creating widgets with a parent **after** the parent is being shown does not automatically show them, so you should also call `label.show()`. – musicamante Jun 26 '23 at 19:15
  • Thanks--that did it for me. (Using label.show()) I'd like to mark this is a solved. – fishbacp Jun 26 '23 at 19:34

0 Answers0