Skip to content

Instantly share code, notes, and snippets.

@4193883-eng
Created October 9, 2022 16:02
Show Gist options
  • Save 4193883-eng/f697b6425d018432da5152557803e199 to your computer and use it in GitHub Desktop.
Save 4193883-eng/f697b6425d018432da5152557803e199 to your computer and use it in GitHub Desktop.
hwbomb
from tkinter import *
score = 0
fuse = 100
pressEnter = True
def start(event):
global pressEnter
global fuse
global score
if not pressEnter:
pass
else:
fuse = 100
score = 0
label.config(text = "")
updateScore()
updateBomb()
updateDisplay()
pressEnter = False
def updateDisplay():
global fuse
global score
if fuse > 50:
bomb_label.config(image= normalPhoto)
elif 0 < fuse <= 50:
bomb_label.config(image=noPhoto)
else:
bomb_label.config(image=pow)
fuse_label.config(text='Fuse' +str(fuse))
score_label.config(text= "Score" +str(score))
fuse_label.after(100, updateDisplay)
def updateBomb():
global fuse
fuse -= 5
if isAlive():
fuse_label.after(400, updateBomb)
def updateScore():
global score
score += 1
if isAlive():
fuse_label.after(3000, updateScore)
def click():
global fuse
if isAlive():
fuse +=1
def isAlive():
global fuse
global pressEnter
if fuse <= 0:
return False
else:
return True
root = Tk()
root.geometry('500x500')
root.title('Bang Bang')
root.config(bg="#cc59d2")
label = Label(root, text = 'Press enter to start the game!!!', font = 'ComicSansMS 14')
fuse_label = Label(root, text = 'Fuse: ' + str(fuse), font = 'ComicSansMS 14')
score_label = Label(root, text = 'Score: '+ str(score), font = 'ComicSansMS 14')
normalPhoto = PhotoImage(file='./bomb_normal.gif')
noPhoto = PhotoImage(file='./bomb_no.gif')
pow = PhotoImage(file='./pow.gif')
bomb_label = Label(root, image=normalPhoto)
click_button = Button(root, text='Click me!!!!!!', command=click)
label.pack()
score_label.pack()
fuse_label.pack()
bomb_label.pack()
click_button.pack()
root.bind('<Return>', start)
root.bind('<S>', click)
root.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment