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
| import random
from tkinter import *
root = Tk()
root.title('Jeu de Casino')
#Item 1 est la mise
mise_box = IntVar()
mise_txt =Label(root, text="Votre mise :")
mise_txt.grid(row=0,sticky=E)
mise_box = Spinbox(root, state='readonly', from_= 1, to = 100, width = 5)
mise_box.grid(row = 0, column = 1)
#Item 2 est le nombre sur lequel on mise
item_2 = IntVar()
chiffre_txt=Label(root, text="Votre chiffre :")
chiffre_txt.grid(row=1,sticky=E)
chiffre_box = Spinbox(root, state='readonly' , from_= 1, to = 9, width = 5)
chiffre_box.grid(row = 1, column = 1)
StockArgent=100
#Fonction jeu = fait tourner le programme pour les valeurs choisies
def jeu():
r=str(random.randrange(1,10))
print(r)
#On met la valeur choisie de 1 à 100 dans mise
mise = int(mise_box.get())
#On met la valeur choisie du chiffre de 1 à 9 dans choix
choix = chiffre_box.get()
#Récapitule ce qu'on vient de faire
Resultat= "Tu as misé " + str(mise) + " sur le numero " + str(choix) + "!"
txt.insert(0.0,Resultat)
txt.configure(state='disabled')
argent=StockArgent
#Calculs
if choix==r:
argent=mise*7+mise+argent
#Rend le text editable
txt.configure(state='normal')
txt.insert(3.0,"\nBRAVO ! Il te reste :"+str(argent)+""+"\nLe chiffre gagnant était :"+ str(r) + "!")
#Rend le txt ineditable
txt.configure(state='disabled')
bouton_confirmer.config(state="disabled")
rejouer()
else:
argent=argent-mise
txt.configure(state='normal')
txt.insert(3.0,"\nTu as perdu "+str(mise)+""+"\nIl te reste "+str(argent)+" dans ton porte monnaie."+"\nLe chiffre gagnant était :"+str(r))
txt.configure(state='disabled')
bouton_confirmer.config(state="disabled")
rejouer()
#Veux quitter le jeu
def rejouer_non():
root.destroy()
def rejouer_oui():
#Reset mise_box
txt.configure(state='normal')
txt.delete(0.0,'end')
mise_box = Spinbox(root, state='readonly', from_= 1, to = 100, width = 5)
mise_box.grid(row = 0, column = 1)
#Reset chiffre_box
chiffre_box = Spinbox(root, state='readonly' , from_= 1, to = 9, width = 5)
chiffre_box.grid(row = 1, column = 1)
bouton_confirmer.config(state="normal")
bouton_oui.destroy()
bouton_non.destroy()
rejouer_box.destroy()
def rejouer():
#Text Veux tu rejouer...
rejouer_box =Label(root, text="Voulez-vous rejouer ?")
rejouer_box.grid(row=7,columnspan=3)
#Bouton pour demander si on veut rejouer ici: Oui
bouton_oui = Button(root, text = 'Oui', width = 10, command =rejouer_oui)
bouton_oui.grid(row = 8, column= 1,sticky=E)
#Bouton pour demander si on veut rejouer ici: Non
bouton_non = Button(root, text = 'Non', width = 10, command =rejouer_non)
bouton_non.grid(row = 8, column=2,sticky=W)
#Bouton Confirmer pour faire tourner le programme
bouton_confirmer = Button(root, text = 'Confirmer', width = 20, command =jeu)
bouton_confirmer.grid(row = 1, column = 2)
#Boite de réponses
txt=Text(root, width=40, height=4, wrap=WORD)
txt.grid(row=2, columnspan=3, sticky=W)
root.mainloop() |
Partager