When I want to add a layout in the __init__(self)
function, the program crashes. Sometimes it takes a few seconds. I also get a different error message every time, for example:
double free or corruption (fasttop)
malloc(): memory corruption (fast)
malloc(): invalid next size (unsorted)
So there seems to be a memory problem.
Full program:
import sysimport os.pathfrom threading import Timerfrom PyQt5.QtWidgets import *from PyQt5.QtCore import *from PyQt5.QtGui import *ATTACK_FILE_PATH = "gui/attacking"TIMER = 0.3FONT = "Arial"FONT_SIZE = 50# WindowWINDOW_TITLE = "Attack Status"WIDTH = 1000HEIGHT = 1000# ContentPATH_OFF = "gui/img/smiley.png"PATH_ON = "gui/img/attack.png"PATH_ON_INV = "gui/img/attack_inv.png"TEXT_OFF = "SYN OFF"TEXT_ON = "SYN ON"ORANGE = "#e65100"BLACK = "#000000"GREEN = "#7cb342"class Window(QWidget): run = True # Run/stop loop inverse = False # Use inverted colors def __init__(self): super().__init__() self.setWindowTitle(WINDOW_TITLE) self.resize(WIDTH, HEIGHT) # Icon self.icon = QLabel(self) self.icon.setPixmap(QPixmap(PATH_OFF)) self.setStyleSheet("background-color: " + GREEN) self.icon.setAlignment(Qt.AlignCenter) # Caption Text self.caption = QLabel(self) self.caption.setText(TEXT_OFF) self.caption.setFont(QFont(FONT, FONT_SIZE)) self.caption.setAlignment(Qt.AlignCenter) # Layout self.layout = QVBoxLayout(self) #self.layout.addWidget(self.image) #self.layout.addStretch() #self.layout.addWidget(self.caption) self.show() self.iterate() def iterate(self): # Loop if self.run: Timer(TIMER, self.iterate).start() # Update image and caption if os.path.isfile(ATTACK_FILE_PATH): if self.inverse: self.update(PATH_ON_INV, BLACK, ORANGE, False, TEXT_ON) else: self.update(PATH_ON, ORANGE, BLACK, True, TEXT_ON) else: self.update(PATH_OFF, GREEN, BLACK, self.inverse, TEXT_OFF) def update(self, icon_path, bg_color, text_color, inverse, caption): self.icon.setPixmap(QPixmap(icon_path)) self.setStyleSheet("background-color: " + bg_color) self.caption.setStyleSheet("color: " + text_color) self.inverse = inverse self.caption.setText(caption)if __name__ == "__main__": # Run App app = QApplication(sys.argv) w = Window() app.exec_() # Close App w.run = False sys.exit()