-
Notifications
You must be signed in to change notification settings - Fork 0
/
bingo_logic.py
48 lines (39 loc) · 1.51 KB
/
bingo_logic.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import random
from tkinter import *
root = Tk()
root.configure(background="green")
root.title("Bingo!!!")
root.geometry("360x240")
# Initialize score counters
row_score = 0
column_score = 0
diagonal_score = 0
# Initialize flags to track completed rows, columns, and diagonals
row_completed = [False] * 5
column_completed = [False] * 5
left_diagonal_completed = False
right_diagonal_completed = False
# Importing Bingo logic functions from bingo_logic.py
from bingo_function import check_win
# function to change button color
def change_color(button):
global row_score, column_score, diagonal_score
global row_completed, column_completed, left_diagonal_completed, right_diagonal_completed
# change button color
button.config(bg="green", fg="red", state=DISABLED, relief=SUNKEN, disabledforeground="red")
# Update row, column, diagonal scores and check win
check_win(row_score, column_score, diagonal_score, row_completed, column_completed, left_diagonal_completed, right_diagonal_completed,buttons)
# generate random numbers
data = list(range(1, 26))
random.shuffle(data)
# create buttons for the Bingo card
buttons = []
for i in range(5):
for j in range(5):
num = data[i*5 + j]
txt = "{:^2}".format(num)
button = Button(root, text=txt, fg="green")
button.grid(row=i, column=j, padx=5, pady=5, ipadx=5, ipady=5, sticky="nsew")
buttons.append(button)
button.config(command=lambda b=button: change_color(b)) # Pass button as argument to lambda
root.mainloop()