that is a good way to go, but I was wanting to get that into a GUI window, that I can later make executable. Not sure how to get the results to print in the listbox one after the other. And to have the clear button clear the list box when full.
here's the best I could come up with, though it does not print the results into the listbox
here's the best I could come up with, though it does not print the results into the listbox
import random as rnd import sys from PyQt5.QtWidgets import (QMainWindow, QApplication, QWidget, QPushButton, QGridLayout, QLabel, QLineEdit, QListWidget, QMessageBox) class Window(QMainWindow): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # Container container = QGridLayout() label = QLabel('Odd or Even?') label2 = QLabel('Red or Black?') button = QPushButton('Spin') button2 = QPushButton('clear') button.clicked.connect(lambda: self.printit) button2.clicked.connect(self.clear) self.listbox = QListWidget() container.addWidget(label, 0, 0, 1, 1) container.addWidget(label2, 0, 1, 1, 1) container.addWidget(button, 1, 0, 1, 1) container.addWidget(button2, 1, 1, 1, 2) container.addWidget(self.listbox, 2, 0 ,1 ,2) widget = QWidget() widget.setLayout(container) self.setCentralWidget(widget) def clear(self): self.listbox.clear() def odd_even(): return rnd.choice(['odd', 'even']) def red_black(): return rnd.choice(['red', 'black']) def printit(self): nums = ', '.join(red_black, odd_even) self.listbox.addItem(nums) def main(): app = QApplication(sys.argv) window = Window() window.show() sys.exit(app.exec_()) main()also, it only needs to pick one of each every time you click the button.