I am trying to make a card game. After 1 game, I need to clear QLabel
to start new game.
Following is the summery that I am debugging.
I want to clear all QLabel
with QPushButton
operation. But actually I could remove only the last Qlabel
. Rest of QLabel
still stay.
How Can I remove all QLabel
?
class Main(QMainWindow):
def __init__(self):
super().__init__()
#overall layout
layout = QVBoxLayout()
self.setStyleSheet("background-color:white")
self.card_layout6 = QHBoxLayout()
self.card_w6 = QLabel()
self.card_w6.setPixmap(QPixmap("card.bmp"))
self.card_layout6.addWidget(self.card_w6)
layout.addLayout(self.card_layout6)
bt1_layout = QtWidgets.QGridLayout()
bt1_layout.setContentsMargins(0,0,0,20)
layout.addLayout(bt1_layout)
self.setGeometry(500, 100, 330, 200)
height = 800
width = 800
self.setFixedHeight(height)
self.setFixedWidth(width)
self.request_bt = QPushButton("add card")
self.request_bt.setStyleSheet("background-color:lightblue")
self.request_bt.clicked.connect(self.add_card_layout6)
bt1_layout.addWidget(self.request_bt,0,0)
# Pushbutton for card removal
remove_bt = QPushButton("card reomve")
remove_bt.setStyleSheet("background-color:pink")
bt1_layout.addWidget(remove_bt,3,0)
remove_bt.clicked.connect(self.card_removal)
#overall layout
self.container = QWidget()
self.container.setLayout(layout)
self.setCentralWidget(self.container)
self.show()
def add_card_layout6(self):
global card_w6
self.card_w6 = QLabel()
self.card_w6.setPixmap(QPixmap("card.bmp"))
self.card_layout6.addWidget(self.card_w6)
def card_removal(self):
self.card_w6.clear()