Ahorcado con Python
from Tkinter import *
import random
def ty():
vent2 = Tk()
vent2.title("El Ahorcado 3.0 **INSTRUCCIONES**")
ins0 = Label(vent2, text="\nINSTRUCCIONES", font=30, fg="red")
ins1 = Label(vent2, text="\nClasico juego donde tienes que adivinar las palabras\n", font=16)
ins2 = Label(vent2, text="sino las adivinas haras ahorcar a bartolome\n", font=16, fg="black")
ins3 = Label(vent2, text="1. Selecciona JUGAR\n", font=16)
ins4 = Label(vent2, text="2. Intruduce las letras a ver si estan en la palabra\n", font=16)
ins5 = Label(vent2, text="3. Si te equivocas, apareceran las imagenes que ahorcaran a bart\n", font=16)
ins6 = Label(vent2, text="4. SOLO TIENES 3 INTENTOS\n", font=18)
ins7 = Label(vent2, text="5. Si quieres salir solo presiona QUIT\n", font=16)
ins8 = Label(vent2, text="6. Para SALIR de la AYUDA da click en x\n", font=16)
ins0.pack()
ins1.pack()
ins2.pack()
ins3.pack()
ins4.pack()
ins5.pack()
ins6.pack()
ins7.pack()
ins8.pack()
# def keypress(event):
# global letras
# keyPressed = event.char
# print "You pressed: " + keyPressed
# letras += keyPressed
# print(letras)
letras = ''
fallados = 0
turnos = 3
def juego():
global letras
global fallados
global turnos
turnos = 3
fallados = 0
vent3 = Tk()
vent3.title("El Ahorcado 3.0 Jugando")
vent3.minsize(350, 150)
mitexto = ""
introduce = Label(vent3, text=mitexto, fg="red", font=("arial", 40))
introduce.pack()
label_turnos = Label(vent3, text="intentos = "+str(turnos), fg="blue", font=("arial", 30))
label_turnos.pack()
entrada = open("parrafo.txt", "r")
lista = entrada.read()
palabras = lista.split()
adivinanza = random.choice(palabras)
adivinanza.lower()
vocales = ['a', 'e', 'i', 'o', 'u']
# turnos = 3
letras = random.choice(vocales) + random.choice(vocales)
print(adivinanza)
print(letras)
# fallados = 0
acvf = ""
for letter in adivinanza:
if letter in letras:
acvf += letter
print letter,
else:
acvf += " _"
print "_",
fallados += 1
print
print("acvf:" + acvf)
introduce.config(text=acvf)
def key(event):
print(event.char)
global letras
global fallados
global turnos
letras += event.char
print(letras)
acvf = ""
for letter in adivinanza:
if letter in letras:
acvf += letter
print letter,
else:
acvf += " _"
print "_",
fallados += 1
print
print("acvf:" + acvf)
introduce.config(text=acvf)
if adivinanza == acvf:
introduce.config(text="HAS GANADO", font=30)
if event.char not in adivinanza:
turnos -= 1
label_turnos.config(text="intentos = "+str(turnos))
print("turnos= "+str(turnos))
if turnos < 1:
print("SE ACABO")
introduce.config(text="HAS PERDIDO")
vent3.bind('<Key>', key)
def exit():
vent.destroy()
vent = Tk()
vent.title("El Ahorcado 3.0")
vent.minsize(500, 270)
cua = Frame(vent)
onebutton = Button(cua, text="JUGAR", fg="black", bg="purple", width="20", pady=55, font="arial",
activebackground="orange", command=juego)
onebutton.grid(row=0, column=0)
twobutton = Button(cua, text="INSTRUCCIONES", fg="black", bg="yellow", width="20", pady=35, font="arial",
activebackground="blue", command=ty)
twobutton.grid(row=3, column=0)
threebutton = Button(cua, text="QUIT", fg="black", bg="red", width="20", pady=35, font="arial",
activebackground="green", command=exit)
threebutton.grid(row=4, column=0)
photo = PhotoImage(file="pant.gif")
p = Label(vent, image=photo)
p.pack(side=RIGHT)
cua.pack(side=LEFT)
vent.mainloop()