Python/pyqt5/CODE/qt05x範例程式/qt05_QListWidget.py

31 lines
695 B
Python
Raw Permalink Normal View History

# -*- coding: utf-8 -*-
'''
簡介
PyQT5中QListWidget範例
'''
import sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
class ListWidget(QListWidget):
def clicked(self,item):
QMessageBox.information(self, "ListWidget", "您選擇了:"+item.text())
if __name__ == '__main__':
app = QApplication(sys.argv)
listWidget = ListWidget()
listWidget.resize(300,120)
listWidget.addItem("Item 1");
listWidget.addItem("Item 2");
listWidget.addItem("Item 3");
listWidget.addItem("Item 4");
listWidget.setWindowTitle('QListwidget範例')
listWidget.itemClicked.connect(listWidget.clicked)
listWidget.show()
sys.exit(app.exec_())