Bingo und Python

Vor ein paar Monaten habe ich ein Python-Programm geschrieben, mit Qt als GUI zur Umrechnung von Celsius und Fahrenheit. Jetzt, im Rahmen der Corona Krise, überlegen wir Online-Bingo für Senioren einzurichten. Dafür wollte ich ein Programm schreiben, um die Zahlen zu ziehen. Ich konnte mich aber nicht mehr daran erinnern, was bei Python und Qt zu beachten ist. Außerdem konnte ich mein altes Programm nicht mehr finden. Deshalb stelle ich hier jetzt zum einen das Python-Programm als auch die Datei für Gestaltung der grafischen Oberfläche ein.


import time
import random
import sys
from PyQt5 import QtWidgets, uic
from PyQt5.QtWidgets import QApplication
from PyQt5.uic import *
# Ziehen eine neuen Zahl
def ziehen():
gz=random.random()*75
gezZahl=int(gz+1)
return gezZahl
# Zurücksetzen alle Parameter für ein neues Spiel
def zuruecksetzen():
print('Neues Spiel')
i=0
# a sortierte Liste, usort unsortierte Liste, Durchgnr die wievielte gezogene Kugel
global a
global unsort
global Durchgnr
a = [0]
unsort=[0]
aStr=" "
unsorStr=" "
Durchgnr=0
# Startzeit des Spiels
Startzeit=time.strftime('%H:%M:%S', time.localtime())
print("Startzeit", Startzeit)
Bingo=["B", "I", "N", "G", "O"]
print(Bingo)
print(a,unsort,Durchgang)
print(i)
window.Spalte.setText(" ")
window.gezZahl.setText(" ")
Startzeit=time.strftime('%H:%M:%S', time.localtime())
window.StartZeit.setText(Startzeit)
window.sortierteZahlen.setText(aStr)
window.unsortierteZahlen.setText(unsorStr)
window.Durchgang.setText(str(Durchgnr))
#Ziehung einer neuen Kugel, Hinzugügen zu den Listen, Sortieren in a
def neueZahl():
global Durchgnr
#print(Durchgnr)
Durchgnr=Durchgnr+1
print(a, Durchgnr)
Einsatz=str(Durchgnr)
gueltigeZahl=1
while gueltigeZahl==1 and Durchgnr<76:
#Ziehen einer Zahl
gezZahl=ziehen()
#Prüfen ob vorhanden, falls schon vorhanden Rest übergehen
Test=0
j=1
while j<Durchgnr:
if gezZahl==a[j]:
print("==Doppel")
Test=1
j=j+1
# Wenn Zahl gültig, anhängen, a sortieren und ausgeben
if Test==0:
gueltigeZahl=0
a.append(gezZahl)
unsort.append(gezZahl)
print(a, unsort, Durchgnr, a[Durchgnr])
window.gezZahl.setText(str(gezZahl))
#Berechnung der Spalte der Zahl (1-15 in B, 16 bis 30 in I, usw)
Div=int((gezZahl-1)/15)
# Spalte und Zahl ausgeben
window.Spalte.setText(Bingo[Div])
window.Durchgang.setText(Einsatz)
# Sortieren
i=0
while i<Durchgnr:
if a[Durchgnr-i]<a[Durchgnr-i-1]:
hilfs=a[Durchgnr-i]
a[Durchgnr-i]=a[Durchgnr-i-1]
a[Durchgnr-i-1]=hilfs
i=i+1
print(a)
print(unsort)
aStr=""
unsorStr=""
#Listen erstellen und ausgeben
i=0
while i<=Durchgnr:
aStr=aStr+" "+str(a[i])
unsorStr=unsorStr+" "+str(unsort[i])
i=i+1
print(aStr)
print(unsorStr)
window.sortierteZahlen.setText(aStr)
window.unsortierteZahlen.setText(unsorStr)
#Startparameter
i=1
global a
a = [0]
unsort=[0]
Durchgang=0
Durchgnr=0
Startzeit=time.strftime('%H:%M:%S', time.localtime())
print("Startzeit", Startzeit)
Bingo=["B", "I", "N", "G", "O"]
print(Bingo)
print(a,unsort,Durchgang)
#GUI-Definition
app = QApplication(sys.argv)
window = uic.loadUi("BingoGui.ui")
window.StartZeit.setText(Startzeit)
window.nachste.clicked.connect(neueZahl)
window.neu.clicked.connect(zuruecksetzen)
window.show()
app.exec()

============

und die GUI

============

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>636</width>
<height>754</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>60</x>
<y>160</y>
<width>161</width>
<height>17</height>
</rect>
</property>
<property name="text">
<string>Uhrzeit bei Spielbeginn:</string>
</property>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>60</x>
<y>190</y>
<width>141</width>
<height>17</height>
</rect>
</property>
<property name="text">
<string>Laufende Spielzeit:</string>
</property>
</widget>
<widget class="QLabel" name="label_3">
<property name="geometry">
<rect>
<x>80</x>
<y>240</y>
<width>161</width>
<height>17</height>
</rect>
</property>
<property name="text">
<string>. gezogenen Nummer:</string>
</property>
</widget>
<widget class="QLabel" name="label_4">
<property name="geometry">
<rect>
<x>60</x>
<y>290</y>
<width>191</width>
<height>17</height>
</rect>
</property>
<property name="font">
<font>
<underline>true</underline>
</font>
</property>
<property name="text">
<string>Liste gezogener Nummern</string>
</property>
</widget>
<widget class="QLabel" name="label_5">
<property name="geometry">
<rect>
<x>60</x>
<y>320</y>
<width>67</width>
<height>17</height>
</rect>
</property>
<property name="font">
<font>
<italic>true</italic>
</font>
</property>
<property name="text">
<string>sortiert:</string>
</property>
</widget>
<widget class="QLabel" name="label_6">
<property name="geometry">
<rect>
<x>60</x>
<y>510</y>
<width>101</width>
<height>17</height>
</rect>
</property>
<property name="font">
<font>
<italic>true</italic>
</font>
</property>
<property name="text">
<string>unsortiert</string>
</property>
</widget>
<widget class="QLabel" name="gezZahl">
<property name="geometry">
<rect>
<x>440</x>
<y>190</y>
<width>181</width>
<height>111</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>90</pointsize>
</font>
</property>
<property name="text">
<string/>
</property>
</widget>
<widget class="QLabel" name="Spalte">
<property name="geometry">
<rect>
<x>320</x>
<y>200</y>
<width>91</width>
<height>91</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>90</pointsize>
</font>
</property>
<property name="text">
<string/>
</property>
</widget>
<widget class="QTextEdit" name="sortierteZahlen">
<property name="geometry">
<rect>
<x>60</x>
<y>340</y>
<width>501</width>
<height>151</height>
</rect>
</property>
</widget>
<widget class="QTextEdit" name="unsortierteZahlen">
<property name="geometry">
<rect>
<x>60</x>
<y>530</y>
<width>501</width>
<height>161</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="nachste">
<property name="geometry">
<rect>
<x>140</x>
<y>700</y>
<width>97</width>
<height>33</height>
</rect>
</property>
<property name="text">
<string>Nächste Zahl</string>
</property>
</widget>
<widget class="QPushButton" name="neu">
<property name="geometry">
<rect>
<x>390</x>
<y>700</y>
<width>97</width>
<height>33</height>
</rect>
</property>
<property name="text">
<string>Neues Spiel</string>
</property>
</widget>
<widget class="QLabel" name="label_7">
<property name="geometry">
<rect>
<x>140</x>
<y>10</y>
<width>401</width>
<height>121</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>90</pointsize>
<weight>75</weight>
<bold>true</bold>
<underline>true</underline>
</font>
</property>
<property name="text">
<string>BINGO</string>
</property>
</widget>
<widget class="QLabel" name="Durchgang">
<property name="geometry">
<rect>
<x>60</x>
<y>240</y>
<width>16</width>
<height>17</height>
</rect>
</property>
<property name="text">
<string>0</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
<widget class="QLabel" name="StartZeit">
<property name="geometry">
<rect>
<x>250</x>
<y>160</y>
<width>91</width>
<height>17</height>
</rect>
</property>
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>