Python Forum
help needed running a simple function in pyqt5
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help needed running a simple function in pyqt5
#7
ok that works great, I updated it a bit and almost got it perfect.

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 Numbers')
        label2 = QLabel('How many Spots')
        
        entry = QLineEdit()
        entry.setPlaceholderText('picks')
        entry.setStyleSheet('border: 1px solid black;')

        entry2 = QLineEdit()
        entry2.setPlaceholderText('picks')
        entry2.setStyleSheet('border: 1px solid black;')

        button = QPushButton('Generate')
        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, 2, 0, 1, 2)
        container.addWidget(label2, 1, 0, 1, 1)
        container.addWidget(entry2, 1, 1, 1, 1)
        container.addWidget(self.listbox, 3, 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()
now I am working on replacing the 49 in the for while loop with a second variable. if you could do this easily it would be appreciated. The program is almost complete and functioning the way I would like you did a great job helping just need it to pick a variable amount of numbers from a variable amount of numbers. so example 10 from 80 or 4 from 80 and of course 6 from 49, the common lotteries I will be using it for. thanks again for all the help. I only have Arduino programming experience so python is exciting.
Reply


Messages In This Thread
RE: help needed running a simple function in pyqt5 - by diodes - Feb-15-2022, 05:02 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How To Make A PyQt5 Progress Bar Run While Executing A Function rcwildabeast 1 539 Apr-26-2024, 02:18 AM
Last Post: menator01
  simple tkinter question function call not opening image gr3yali3n 5 3,722 Aug-02-2022, 09:13 PM
Last Post: woooee
  Tkinter won't run my simple function AthertonH 6 4,169 May-03-2022, 02:33 PM
Last Post: deanhystad
  [Tkinter] Have tkinter button toggle on and off a continuously running function AnotherSam 5 5,203 Oct-01-2021, 05:00 PM
Last Post: Yoriz
  A Simple PyQt5 Class zoro 15 5,989 Mar-02-2020, 07:25 PM
Last Post: micseydel
  Refresh image in label after every 1s using simple function jenkins43 1 5,556 Jul-28-2019, 02:49 PM
Last Post: Larz60+
  Huge code problems (buttons(PyQt5),PyQt5 Threads, Windows etc) ZenWoR 0 2,928 Apr-06-2019, 11:15 PM
Last Post: ZenWoR

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020