Feb-15-2022, 09:21 AM
Here is an example of what you want I think. I did not do any kind of validation on what is being entered. text will probably crash it.
import random as rnd import sys from PyQt5.QtWidgets import (QMainWindow, QApplication, QWidget, QPushButton, QGridLayout, QLabel, QLineEdit, QListWidget) class Window(QMainWindow): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # Container container = QGridLayout() label = QLabel('How many spots') entry = QLineEdit() entry.setPlaceholderText('Enter a number here') entry.setStyleSheet('border: 1px solid black;') button = QPushButton('Submit') button.clicked.connect(lambda: self.picker(entry)) self.listbox = QListWidget() container.addWidget(label, 0, 0, 1, 1) container.addWidget(entry, 0, 1, 1, 1) container.addWidget(button, 1, 0, 1, 2) container.addWidget(self.listbox, 2, 0, 1, 2) widget = QWidget() widget.setLayout(container) self.setCentralWidget(widget) def picker(self, spots): spots = int(spots.text()) picks = [] while len(picks) < spots: pick = rnd.randint(1, 49) if pick not in picks: picks.append(f'{pick}') nums = ', '.join(picks) self.listbox.addItem(nums) def main(): app = QApplication(sys.argv) window = Window() window.show() sys.exit(app.exec_()) main()
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags