Created
April 22, 2016 15:14
-
-
Save hackerdem/dde1d49a9140d276f82cb7459be5d5b3 to your computer and use it in GitHub Desktop.
bingo board with gui, simpl python programming example including tkinter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
from tkinter import * | |
chosen_number_list=[] | |
numbers=[] | |
for i in range(1,101): | |
numbers.append(i) | |
def random_number_selection(): | |
global c | |
c=[] | |
c=random.sample(numbers,1) | |
numbers.remove(c[0]) | |
text1.delete('1.0',END) | |
text1.insert(INSERT,c[0]) | |
def number_delete(): | |
try: | |
for i in range(len(listo)): | |
if listo[i]==c[0]: | |
text1.delete('1.0',END) | |
if str(lab1.cget("text"))==str(c[0]): | |
lab1.config(bg="red") | |
elif str(lab2.cget("text"))==str(c[0]): | |
lab2.config(bg="red") | |
elif str(lab3.cget("text"))==str(c[0]): | |
lab3.config(bg="red") | |
elif str(lab4.cget("text"))==str(c[0]): | |
lab4.config(bg="red") | |
elif str(lab5.cget("text"))==str(c[0]): | |
lab5.config(bg="red") | |
elif str(lab6.cget("text"))==str(c[0]): | |
lab6.config(bg="red") | |
elif str(lab7.cget("text"))==str(c[0]): | |
lab7.config(bg="red") | |
elif str(lab8.cget("text"))==str(c[0]): | |
lab8.config(bg="red") | |
elif str(lab9.cget("text"))==str(c[0]): | |
lab9.config(bg="red") | |
else: | |
text1.delete('1.0',END) | |
text1.insert(INSERT,"This number is not in your card") | |
except Exception: | |
text1.delete('1.0',END) | |
text1.insert(INSERT,"Please draw a number firstly") | |
main_win.update() | |
def chose_num(): | |
listo=[] | |
while (len(listo)<=9): | |
k=random.choice(range(1,101)) | |
if k not in listo:listo.append(k) | |
return listo | |
if __name__=='__main__': | |
listo=chose_num() | |
main_win=Tk() | |
main_win.title('Your Bingo Bord') | |
#message area | |
text1=Text(main_win,width=47,height=1,bg='grey') | |
text1.pack() | |
#number set 1 | |
can1=Canvas(main_win,width=100,height=70,bg='white') | |
lab1=Label(can1, text=listo[0],width=10) | |
lab1.pack() | |
lab2=Label(can1, text=listo[1],width=10,) | |
lab2.pack() | |
lab3=Label(can1, text=listo[2],width=10) | |
lab3.pack() | |
can1.pack(side=LEFT) | |
#number set 2 | |
can2=Canvas(main_win,width=100,height=70,bg='white') | |
lab4=Label(can2, text=listo[3],width=10) | |
lab4.pack() | |
lab5=Label(can2, text=listo[4],width=10) | |
lab5.pack() | |
lab6=Label(can2, text=listo[5],width=10) | |
lab6.pack() | |
can2.pack(side=LEFT) | |
#number set 1 | |
can3=Canvas(main_win,width=100,height=70,bg='white') | |
lab7=Label(can3, text=listo[6],width=10) | |
lab7.pack() | |
lab8=Label(can3, text=listo[7],width=10) | |
lab8.pack() | |
lab9=Label(can3, text=listo[8],width=10) | |
lab9.pack() | |
can3.pack(side=LEFT) | |
#button set | |
bou1=Button(main_win,text='Quit',width=20,command=main_win.quit) | |
bou1.pack() | |
bou2=Button(main_win,text='Draw A Number',width=20,command=random_number_selection) | |
bou2.pack(side=BOTTOM) | |
bou3=Button(main_win,text='Delete A Number',width=20,command=number_delete) | |
bou3.pack(side=BOTTOM) | |
main_win.mainloop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment