import
sys
from
PyQt5.QtWidgets
import
*
class
ListBox(QWidget):
def
__init__(
self
):
super
().__init__()
self
.initUI()
def
initUI(
self
):
vbox
=
QVBoxLayout(
self
)
hbox
=
QHBoxLayout()
self
.listWidget
=
QListWidget(
self
)
self
.listWidget.addItems(
[
'python'
,
'c++'
,
'java'
,
'pyqt5'
,
'javascript'
,
'geeksforgeeks'
])
clear_btn
=
QPushButton(
'Clear'
,
self
)
clear_btn.clicked.connect(
self
.clearListWidget)
vbox.addWidget(
self
.listWidget)
hbox.addWidget(clear_btn)
vbox.addLayout(hbox)
self
.setLayout(vbox)
self
.setGeometry(
300
,
300
,
350
,
250
)
self
.setWindowTitle(
'QListWidget'
)
self
.show()
def
clearListWidget(
self
):
self
.listWidget.clear()
if
__name__
=
=
'__main__'
:
app
=
QApplication(sys.argv)
ex
=
ListBox()
sys.exit(app.exec_())