Nov-04-2024, 09:57 PM
(This post was last modified: Nov-04-2024, 09:57 PM by deanhystad.)
Can you post a screenshot without maximizing the Bingo Caller window? I don't know what is going on with your program. When I run the posted code I get a fairly small window with a "Call Number" button centered slightly below the "Press 'Call Number' to start" text. When I press the button it replaces the "Press 'Call Number' to start" text with the called number ("B13" for example). How are you running the program, do you double click on the .py file or do you run it from the command line like python bingocaller.py?
Repeated sequences should not be a problem. I ran your code 1,000,000 times and the number sequence didn't repeat once. This is not surprising as the number of possible bingo sequences is huge. The number of ways you can randomly draw 72 bingo balls is 72! / (72 - 24)! = 4.9327271416e+42. I would have to run my test program billions of times to have any possibility of finding a repeating sequence of numbers. It is very, very, very unlikely that your program is generating two bingo games that are the same.
It is not unlikely that sequences of numbers will repeat. When I play 100 bingo games and compare the sequences of balls drawn it is not uncommon to see sequences of 2 or 3 balls that appear in two different games. A player might remember B13, N35, G50 and think the balls are falling in the same order, not remembering that this was 5 calls into one game and 15 calls into another. They may also remember N35, B13, G50 as being called in a previous game and think that is a match. Our minds are programmed to find patterns.
I added displays to show the called numbers. A list of the numbers displayed in the order called, and a sorted list of called numbers for each letter. I've called bingo and know how important it is to have accurate records.
Repeated sequences should not be a problem. I ran your code 1,000,000 times and the number sequence didn't repeat once. This is not surprising as the number of possible bingo sequences is huge. The number of ways you can randomly draw 72 bingo balls is 72! / (72 - 24)! = 4.9327271416e+42. I would have to run my test program billions of times to have any possibility of finding a repeating sequence of numbers. It is very, very, very unlikely that your program is generating two bingo games that are the same.
It is not unlikely that sequences of numbers will repeat. When I play 100 bingo games and compare the sequences of balls drawn it is not uncommon to see sequences of 2 or 3 balls that appear in two different games. A player might remember B13, N35, G50 and think the balls are falling in the same order, not remembering that this was 5 calls into one game and 15 calls into another. They may also remember N35, B13, G50 as being called in a previous game and think that is a match. Our minds are programmed to find patterns.
I added displays to show the called numbers. A list of the numbers displayed in the order called, and a sorted list of called numbers for each letter. I've called bingo and know how important it is to have accurate records.
import random import tkinter as tk class BingoLetter(tk.Label): """Display called numbers for a letter.""" def __init__(self, parent, letter, **kwargs): super().__init__(parent, text="", anchor="w", **kwargs) self.letter = letter self.numbers = [] self.update_text() def clear(self): """Clear the called numbers.""" self.numbers.clear() self.update_text() def add_number(self, number): """Add number to the label.""" self.numbers.append(int(number[1:])) self.update_text() def update_text(self): """Update label text to show called numbers.""" self.config(text=f"{self.letter}: {str(sorted(self.numbers))[1:-1]}") class Bingo(tk.Tk): """Window for calling bingo numbers.""" all_numbers = ( ["B" + str(i) for i in range(1, 16)] + ["I" + str(i) for i in range(16, 31)] + ["N" + str(i) for i in range(31, 46)] + ["G" + str(i) for i in range(46, 61)] + ["O" + str(i) for i in range(61, 76)] ) def __init__(self): super().__init__() self.title("Bingo Caller") self.bingo_numbers = [] self.last_number = tk.Label(self, text="Press 'Call Number' to start", font=("Helvetica", 18)) self.called_numbers = tk.Text(self, width=50, height=7, wrap=tk.WORD, font=("Courier", 16)) self.letters = { "B": BingoLetter(self, "B", font=("Courier", 12)), "I": BingoLetter(self, "I", font=("Courier", 12)), "N": BingoLetter(self, "N", font=("Courier", 12)), "G": BingoLetter(self, "G", font=("Courier", 12)), "O": BingoLetter(self, "O", font=("Courier", 12)), } buttons = tk.Frame(self) self.call_button = tk.Button(buttons, text="Call Number", command=self.call_number, font=("Helvetica", 18)) self.restart_button = tk.Button(buttons, text="New Game", command=self.new_game, font=("Helvetica", 18)) self.last_number.pack(side="top", padx=10, pady=(10, 0)) self.called_numbers.pack(side="top", padx=10, pady=10) for letter in self.letters.values(): letter.pack(side="top", padx=10, expand=True, fill=tk.X) buttons.pack(side="top", padx=10, pady=10) self.call_button.pack(side="left") self.restart_button.pack(side="left", padx=(10, 0)) self.new_game() def call_number(self): """Called when "Call Number" button is pressed.""" if self.bingo_numbers: # Get next number and update displays. number = self.bingo_numbers.pop() self.last_number.config(text=number) self.called_numbers.insert(tk.END, f"{number: <3} ") self.letters[number[0]].add_number(number) else: # No more numbers. Notify user. self.last_number.config(text="All numbers have been called.") self.call_button.config(state="disabled") def new_game(self): """Start a new game.""" self.last_number.config(text="Press 'Call Number' to start") self.bingo_numbers = random.sample(self.all_numbers, len(self.all_numbers)) self.called_numbers.delete(1.0, tk.END) for letter in self.letters.values(): letter.clear() self.call_button.config(state="normal") Bingo().mainloop()