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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
| from tkinter import *
import tkinter.font as tkFont
from random import randint
fen = Tk()
fen.geometry('985x540+10+10')
fen.title('Jeu Shifumi')
file_ciseaux = 'images//ciseaux.png'
img_ciseaux = PhotoImage(file=file_ciseaux)
file_feuille = 'images//feuille.png'
img_feuille = PhotoImage(file=file_feuille)
file_pierre = 'images//pierre.png'
img_pierre = PhotoImage(file=file_pierre)
can = Canvas(fen, width=984, height=328)
id_ciseaux = can.create_image(0, 0, image=img_ciseaux, anchor=NW)
id_feuille = can.create_image(328, 0, image=img_feuille, anchor=NW)
id_pierre = can.create_image(656, 0, image=img_pierre, anchor=NW)
can.grid(row=0, column=0, columnspan=3)
choix_ordi = {
"1":"Pierre",
"2":"Papier",
"3":"Ciseaux"
}
def button_disable():
bouton_jouer.config(state="disabled")
def choisir_pierre(c_p):
choix = choix_ordi[str(randint(1,3))]
if choix == "Pierre":
résultat = "Il y a égalité"
elif choix=="Ciseaux":
résultat = "Bravo ! Tu as gagné !"
else:
résultat = "L'ordi remporte cette partie"
label_gagnant.config(text = résultat)
label_joueur.configure(image = img_pierre)
label_ordi.config(text = choix)
button_disable()
def choisir_feuille(c_f):
choix = choix_ordi[str(randint(1,3))]
if choix == "Feuille":
résultat = "Il y a égalité"
elif choix=="Ciseaux":
résultat = "L'ordi remporte cette partie"
else:
résultat = "Bravo ! Tu as gagné !"
label_gagnant.config(text = résultat)
label_joueur.configure(image = img_feuille)
label_ordi.config(text = choix)
button_disable()
def choisir_ciseaux(c_c):
choix = choix_ordi[str(randint(1,3))]
if choix == "Pierre":
résultat = "L'ordi remporte cette partie"
elif choix=="Ciseaux":
résultat = "Il y a égalité"
else:
résultat = "Bravo ! Tu as gagné !"
label_gagnant.config(text = résultat)
label_joueur.configure(image = img_ciseaux)
label_ordi.config(text = choix)
button_disable()
def rejouer():
bouton_jouer.config(state= "active")
label_joueur.config(text = "Choix du joueur: ")
label_ordi.config(text = "Choix de l\'ordinateur: ")
can.tag_bind(id_ciseaux, '<ButtonRelease-1>', choisir_ciseaux)
can.tag_bind(id_feuille, '<ButtonRelease-1>', choisir_feuille)
can.tag_bind(id_pierre, '<ButtonRelease-1>', choisir_pierre)
helv18 = tkFont.Font(family='Helvetica', size=18, weight='bold')
helv14 = tkFont.Font(family='Helvetica', size=14, weight='bold')
label_joueur = Label(fen, text='Choix du joueur: ', width=25, anchor='w', pady=20, font=helv14)
label_joueur.grid(row=1, column=0)
label_ordi = Label(fen, text='Choix de l\'ordinateur: ', width=25, anchor='w', pady=20, font=helv14)
label_ordi.grid(row=1, column=2)
label_gagnant = Label(fen, text='Résultat', width=25, anchor='center', pady=20, font=helv14)
label_gagnant.grid(row=2, column=1)
def lancer_jeu():
choix = randint(1,3)
if choix == 1:
label_ordi.configure(image=img_pierre)
elif choix == 2:
label_ordi.configure(image=img_feuille)
else:
label_ordi.configure(image=img_ciseaux)
bouton_jouer = Button(fen, text='Jouer', command=lancer_jeu, font=helv18)
bouton_jouer.grid(row=3, column=1)
start = False
def afficher_choix_ordi(n_o):
chaine = 'Choix de l\ordinateur: ' + choix[n_o]
label_joueur.configure(text=chaine)
rejouer = Button(text= "Rejouer", width= 7, font= 10, command=rejouer)
rejouer.grid(row=2, column=2)
fen.mainloop() |
Partager