import sys
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QCheckBox
class CheckBoxWindow(QWidget):
def __init__(self, items):
super().__init__()
# Set the window properties
self.setWindowTitle('Checkbox Example')
self.setGeometry(100, 100, 280, 200)
# Create a QVBoxLayout instance
layout = QVBoxLayout()
# Add checkboxes to the layout for each item in the list
self.checkboxes = []
for item in items:
checkbox = QCheckBox(item, self)
layout.addWidget(checkbox)
self.checkboxes.append(checkbox)
# Set the layout for the main window
self.setLayout(layout)
# Show the window
self.show()
# Your list of items
items = ["Checkbox 1", "Checkbox 2", "Checkbox 3", "Checkbox 4", "Checkbox 5"]
def main():
# Create a PyQt5 application
app = QApplication(sys.argv)
# Create an instance of CheckBoxWindow
window = CheckBoxWindow(items)
# Execute the application
sys.exit(app.exec_())
if __name__ == '__main__':
main()
This script initializes a window with a vertical list of checkboxes corresponding to the items in your items list. When you run the script, you should see a window with a list of checkboxes labeled "Checkbox 1" to "Checkbox 5". You can modify the items list to contain any strings you need for your application.