SlideShare a Scribd company logo
1 of 2
Download to read offline
from tkinter import *
from PIL import Image, ImageTk
from string import ascii_uppercase
import random
from tkinter import messagebox
root=Tk()
root.geometry("1050x550")
root.title('Hangman')
bg=ImageTk.PhotoImage(Image.open('BG.png'))
a=Label(root,image=bg)
a.place(x=0,y=0)
l=['apple','banana','orange','watermelon','cherry','strawberry','bottle','ball','pendrive','webcam']
s='.png'
s
score=0
word='a'
def update():
global word
num=random.randint(1,7)
word=l[num]+s
img = PhotoImage(file=word)
imcon=canvas.create_image(20,20, anchor=NW, image=img)
canvas.itemconfig(imcon,image=word)
return word
canvas = Canvas(root, width = 140, height = 140)
canvas.place(x=820,y=90)
namevalue= StringVar()
ent_name = Entry(root, width=70, borderwidth=10, textvariable=namevalue)
ent_name.place(x=150, y=150)
def check():
global score
value=ent_name.get()
a=word.rstrip('.png')
from PIL import Image, ImageTk
from string import ascii_uppercase
import random
from tkinter import messagebox
root = Tk()
root.title(' RESULT ')
root.geometry('250x100')
root.resizable(0, 0)
root.configure(bg='grey')
if value==a:
lab = Label(root, text='YOUn WONn :)', bg='black', fg='white', width=25, font=('Arial', 13))
lab.place(x=10,y=15)
score+=1
else:
lab = Label(root, text='YOUn LOSEn :(', bg='black', fg='white', width=25, font=('Arial', 13))
lab.place(x=10,y=15)
root.mainloop()
def clear():
namevalue.set('')
def win():
global score
a='Your Score: '+str(score)
labe = Label(root, text=a, bg='black', fg='white', width=25, font=('Arial', 13))
labe.place(x=10,y=15)
def close():
root.quit()
button = Button(root, text='CHECK',command=check,font=("impact", 20), bg='orange', fg='white', bd=0)
button.place(x=750, y=440)
button1 = Button(root, text='VIEW SCORE',command=win, font=("impact", 20), bg='#201c4e', fg='white', bd=0)
button1.place(x=850, y=440)
button2 = Button(root, text='CLEAR ENTRY',command=clear, font=("impact", 15), bg='black', fg='white', bd=0)
button2.place(x=300, y=200)
button3 = Button(root, text='CHANGE IMAGE',command=update, font=("impact", 15), bg='GREEN', fg='white', bd=0)
button3.place(x=830, y=240)
Button(root, text= "EXIT!!", font=("Calibri",14,"bold"),
command=close,bg='red',fg='white',activebackground='grey').pack(pady=20)
root.mainloop()
root.mainloop()

More Related Content

Similar to Hangman Code.pdf

You are task to add a yawning detection to the programme below;i.pdf
You are task to add a yawning detection to the programme below;i.pdfYou are task to add a yawning detection to the programme below;i.pdf
You are task to add a yawning detection to the programme below;i.pdf
sales223546
 
Can someone please explain what the code below is doing and comment on.pdf
Can someone please explain what the code below is doing and comment on.pdfCan someone please explain what the code below is doing and comment on.pdf
Can someone please explain what the code below is doing and comment on.pdf
kuldeepkumarapgsi
 
Using the code below- I need help with creating code for the following.pdf
Using the code below- I need help with creating code for the following.pdfUsing the code below- I need help with creating code for the following.pdf
Using the code below- I need help with creating code for the following.pdf
acteleshoppe
 
Need helping adding to the code below to plot the images from the firs.pdf
Need helping adding to the code below to plot the images from the firs.pdfNeed helping adding to the code below to plot the images from the firs.pdf
Need helping adding to the code below to plot the images from the firs.pdf
actexerode
 
openFrameworks 007 - graphics
openFrameworks 007 - graphicsopenFrameworks 007 - graphics
openFrameworks 007 - graphics
roxlu
 
circ.db.dbcircleserver(1).py#!usrlocalbinpython3im.docx
circ.db.dbcircleserver(1).py#!usrlocalbinpython3im.docxcirc.db.dbcircleserver(1).py#!usrlocalbinpython3im.docx
circ.db.dbcircleserver(1).py#!usrlocalbinpython3im.docx
christinemaritza
 

Similar to Hangman Code.pdf (20)

You are task to add a yawning detection to the programme below;i.pdf
You are task to add a yawning detection to the programme below;i.pdfYou are task to add a yawning detection to the programme below;i.pdf
You are task to add a yawning detection to the programme below;i.pdf
 
Making Games in JavaScript
Making Games in JavaScriptMaking Games in JavaScript
Making Games in JavaScript
 
Can someone please explain what the code below is doing and comment on.pdf
Can someone please explain what the code below is doing and comment on.pdfCan someone please explain what the code below is doing and comment on.pdf
Can someone please explain what the code below is doing and comment on.pdf
 
Using the code below- I need help with creating code for the following.pdf
Using the code below- I need help with creating code for the following.pdfUsing the code below- I need help with creating code for the following.pdf
Using the code below- I need help with creating code for the following.pdf
 
The Ring programming language version 1.3 book - Part 43 of 88
The Ring programming language version 1.3 book - Part 43 of 88The Ring programming language version 1.3 book - Part 43 of 88
The Ring programming language version 1.3 book - Part 43 of 88
 
29-kashyap-mask-detaction.pptx
29-kashyap-mask-detaction.pptx29-kashyap-mask-detaction.pptx
29-kashyap-mask-detaction.pptx
 
Denis Sergienko "Pip install driven deep learning"
Denis Sergienko "Pip install driven deep learning"Denis Sergienko "Pip install driven deep learning"
Denis Sergienko "Pip install driven deep learning"
 
Need helping adding to the code below to plot the images from the firs.pdf
Need helping adding to the code below to plot the images from the firs.pdfNeed helping adding to the code below to plot the images from the firs.pdf
Need helping adding to the code below to plot the images from the firs.pdf
 
Game dev 101 part 3
Game dev 101 part 3Game dev 101 part 3
Game dev 101 part 3
 
imager package in R and examples..
imager package in R and examples..imager package in R and examples..
imager package in R and examples..
 
Expand/Collapse animation on Android
Expand/Collapse animation on AndroidExpand/Collapse animation on Android
Expand/Collapse animation on Android
 
Immutable Libraries for React
Immutable Libraries for ReactImmutable Libraries for React
Immutable Libraries for React
 
Standford 2015 week3: Objective-C Compatibility, Property List, Views
Standford 2015 week3: Objective-C Compatibility, Property List, ViewsStandford 2015 week3: Objective-C Compatibility, Property List, Views
Standford 2015 week3: Objective-C Compatibility, Property List, Views
 
Python GUI Programming
Python GUI ProgrammingPython GUI Programming
Python GUI Programming
 
The Ring programming language version 1.3 book - Part 32 of 88
The Ring programming language version 1.3 book - Part 32 of 88The Ring programming language version 1.3 book - Part 32 of 88
The Ring programming language version 1.3 book - Part 32 of 88
 
openFrameworks 007 - graphics
openFrameworks 007 - graphicsopenFrameworks 007 - graphics
openFrameworks 007 - graphics
 
The Ring programming language version 1.5.2 book - Part 52 of 181
The Ring programming language version 1.5.2 book - Part 52 of 181The Ring programming language version 1.5.2 book - Part 52 of 181
The Ring programming language version 1.5.2 book - Part 52 of 181
 
The Ring programming language version 1.6 book - Part 44 of 189
The Ring programming language version 1.6 book - Part 44 of 189The Ring programming language version 1.6 book - Part 44 of 189
The Ring programming language version 1.6 book - Part 44 of 189
 
circ.db.dbcircleserver(1).py#!usrlocalbinpython3im.docx
circ.db.dbcircleserver(1).py#!usrlocalbinpython3im.docxcirc.db.dbcircleserver(1).py#!usrlocalbinpython3im.docx
circ.db.dbcircleserver(1).py#!usrlocalbinpython3im.docx
 
HTML 5_Canvas
HTML 5_CanvasHTML 5_Canvas
HTML 5_Canvas
 

Recently uploaded

Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...
Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...
Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...
Lisi Hocke
 

Recently uploaded (20)

Effective Strategies for Wix's Scaling challenges - GeeCon
Effective Strategies for Wix's Scaling challenges - GeeConEffective Strategies for Wix's Scaling challenges - GeeCon
Effective Strategies for Wix's Scaling challenges - GeeCon
 
Driving Innovation: Scania's API Revolution with WSO2
Driving Innovation: Scania's API Revolution with WSO2Driving Innovation: Scania's API Revolution with WSO2
Driving Innovation: Scania's API Revolution with WSO2
 
Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...
Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...
Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
Novo Nordisk: When Knowledge Graphs meet LLMs
Novo Nordisk: When Knowledge Graphs meet LLMsNovo Nordisk: When Knowledge Graphs meet LLMs
Novo Nordisk: When Knowledge Graphs meet LLMs
 
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
WSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AIWSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AI
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of TransformationWSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
WSO2CON 2024 - Building a Digital Government in Uganda
WSO2CON 2024 - Building a Digital Government in UgandaWSO2CON 2024 - Building a Digital Government in Uganda
WSO2CON 2024 - Building a Digital Government in Uganda
 
WSO2Con2024 - Unleashing the Financial Potential of 13 Million People
WSO2Con2024 - Unleashing the Financial Potential of 13 Million PeopleWSO2Con2024 - Unleashing the Financial Potential of 13 Million People
WSO2Con2024 - Unleashing the Financial Potential of 13 Million People
 

Hangman Code.pdf

  • 1. from tkinter import * from PIL import Image, ImageTk from string import ascii_uppercase import random from tkinter import messagebox root=Tk() root.geometry("1050x550") root.title('Hangman') bg=ImageTk.PhotoImage(Image.open('BG.png')) a=Label(root,image=bg) a.place(x=0,y=0) l=['apple','banana','orange','watermelon','cherry','strawberry','bottle','ball','pendrive','webcam'] s='.png' s score=0 word='a' def update(): global word num=random.randint(1,7) word=l[num]+s img = PhotoImage(file=word) imcon=canvas.create_image(20,20, anchor=NW, image=img) canvas.itemconfig(imcon,image=word) return word canvas = Canvas(root, width = 140, height = 140) canvas.place(x=820,y=90) namevalue= StringVar() ent_name = Entry(root, width=70, borderwidth=10, textvariable=namevalue) ent_name.place(x=150, y=150) def check(): global score value=ent_name.get() a=word.rstrip('.png') from PIL import Image, ImageTk from string import ascii_uppercase import random from tkinter import messagebox root = Tk() root.title(' RESULT ') root.geometry('250x100') root.resizable(0, 0) root.configure(bg='grey') if value==a: lab = Label(root, text='YOUn WONn :)', bg='black', fg='white', width=25, font=('Arial', 13)) lab.place(x=10,y=15) score+=1 else: lab = Label(root, text='YOUn LOSEn :(', bg='black', fg='white', width=25, font=('Arial', 13)) lab.place(x=10,y=15)
  • 2. root.mainloop() def clear(): namevalue.set('') def win(): global score a='Your Score: '+str(score) labe = Label(root, text=a, bg='black', fg='white', width=25, font=('Arial', 13)) labe.place(x=10,y=15) def close(): root.quit() button = Button(root, text='CHECK',command=check,font=("impact", 20), bg='orange', fg='white', bd=0) button.place(x=750, y=440) button1 = Button(root, text='VIEW SCORE',command=win, font=("impact", 20), bg='#201c4e', fg='white', bd=0) button1.place(x=850, y=440) button2 = Button(root, text='CLEAR ENTRY',command=clear, font=("impact", 15), bg='black', fg='white', bd=0) button2.place(x=300, y=200) button3 = Button(root, text='CHANGE IMAGE',command=update, font=("impact", 15), bg='GREEN', fg='white', bd=0) button3.place(x=830, y=240) Button(root, text= "EXIT!!", font=("Calibri",14,"bold"), command=close,bg='red',fg='white',activebackground='grey').pack(pady=20) root.mainloop() root.mainloop()