/
piedra-papel-tijera-gui.py
84 lines (71 loc) · 2.58 KB
/
piedra-papel-tijera-gui.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# !/usr/bin/env python
# -*-coding:utf-8-*-
import random
import sys
from Tkinter import *
# vector con todas cada string en Mayusculas
vector = ['PIEDRA', 'PAPEL', 'TIJERA', 'LAGARTO', 'SPOCK']
# Funcion que se ejecuta cuando se da click en el boton
def hacer_click():
eleccion = opcion.get()
eleccion = eleccion.upper() # convertir en Mayusculas
if eleccion not in vector: # -----------------|condicional que valida
etiqueta.config(text="Valor incorrecto") # |si se encuentra esa
else: # -----------------------------------------|palabra en el vector
pc = random.choice(vector)
etiqueta_4.config(text=pc)
if eleccion == pc:
etiqueta.config(text="Empate :| ")
elif eleccion == "PIEDRA":
if pc == "TIJERA" or pc == "LAGARTO":
etiqueta.config(text="Ganaste :) ")
else:
etiqueta.config(text="Perdiste:")
elif eleccion == "PAPEL":
if pc == "PIEDRA" or pc == "SPOCK":
etiqueta.config(text="Ganaste :) ")
else:
etiqueta.config(text="Perdiste:")
elif eleccion == "TIJERA":
if pc == "PAPEL" or pc == "LAGARTO":
etiqueta.config(text="Ganaste :) ")
else:
etiqueta.config(text="Perdiste:")
elif eleccion == "LAGARTO":
if pc == "SPOCK" or pc == "PAPEL":
etiqueta.config(text="Ganaste :) ")
else:
etiqueta.config(text="Perdiste:")
elif eleccion == "SPOCK":
if pc == "TIJERAS" or pc == "PIEDRA":
etiqueta.config(text="Ganaste :) ")
else:
etiqueta.config(text="Perdiste:")
app = Tk()
app.title('Mi primera App grafica')
vp = Frame(app)
vp.grid(row=0, column=0, padx=(50, 50), pady=(10, 10))
vp.columnconfigure(0, weight=1)
vp.rowconfigure(0, weight=1)
etiqueta1 = Label(vp, text="PIEDRA,PAPEL,TIJERA")
etiqueta1.grid(row=1, column=1)
etiqueta_2 = Label(vp, text="LAGARTO,SPOCK")
etiqueta_2.grid(row=1, column=2)
# pc eligio:
etiqueta_3 = Label(vp, text="PC eligio:")
etiqueta_3.grid(row=3, column=1)
# Da la opcion que eligio la computadora
etiqueta_4 = Label(vp, text="")
etiqueta_4.grid(row=3, column=2)
# Muestra si Ganaste o Perdiste
etiqueta = Label(vp, text="")
etiqueta.grid(row=5, column=1)
# caja donde se recoge la informacion
valor = ""
opcion = Entry(vp, width=10, textvariable=valor)
opcion.grid(row=2, column=1)
# boton para validar
boton = Button(vp, text="click!", command=hacer_click)
boton.grid(row=2, column=2)
app.mainloop()
Status