Accueil > > > IMITATION DU JEU DE DÉDÉ
IMITATION DU JEU DE DÉDÉ
Information sur la source
Description
Voici un petit code avec une interface graphique Tk qui permet d'imiter le jeu Dédé de la Française des jeux. Ce code est assez simple. Il en existe plusieurs version (2) : une avec Pmw et une autre sans utiliser la bibliothèque Pmw
Source
- # -*- coding:Utf-8 -*-
-
- #################
- # Aéra group #
- # #
- # Imitation du #
- # jeu Dédé #
- # Version 1.1 #
- #################
-
-
- #---------------------- Créé le dimanche 20 août 2006 ----------------------#
- #-------------- Dernière mise à jour : le 20 août 2006 --------------#
-
-
- #======================== PROGRAMME PYTHON : ========================#
-
-
-
-
-
-
- # ===== 1. Importation ===== #
-
-
-
- from Tkinter import *
- import Pmw
- from random import *
- from tkMessageBox import askyesno
- import tkMessageBox
-
-
-
- # ===== 2. Fonctions préliminaires ===== #
-
- def nouv():
- global bn, ar, ars, tk, cou, coup
- ans=askyesno('Nouvelle partie',"Voulez-vous réellement recommencer une nouvelle partie ? \nVotre progression actuelle sera perdu")
- if ans:
- can.delete(ALL)
- can1.delete(ALL)
- bn=0
- ar=2
- ars=0
- tk=1
- cou=0
- coup=0
- b1.configure(state=NORMAL)
- b2.configure(state=NORMAL)
- b3.configure(state=NORMAL)
- b4.configure(state=DISABLED)
- l.configure(text='Nombre de ticket acheté : ' + str(tk))
- l1.configure(text='Argent perdu : ' + str(ars) + ' €')
- l2.configure(text='Coup(s) gagnant(s) : ' + str(cou))
- l3.configure(text='Coup(s) perdant(s) : ' + str(coup))
- l4.configure(text='Argent disponible : ' + str(ar) + ' €',fg='black')
- ch.configure(text='')
- ch1.configure(text='')
-
-
-
- def dessin1():
- can.delete(ALL)
- can.create_rectangle(10,10,190,190,fill='grey90')
- can.create_oval(80,80,120,120,fill='black')
-
- def dessin2():
- can.delete(ALL)
- can.create_rectangle(10,10,190,190,fill='grey90')
- can.create_oval(30,30,70,70,fill='black')
- can.create_oval(130,130,170,170,fill='black')
-
- def dessin3():
- can.delete(ALL)
- can.create_rectangle(10,10,190,190,fill='grey90')
- can.create_oval(80,80,120,120,fill='black')
- can.create_oval(30,30,70,70,fill='black')
- can.create_oval(130,130,170,170,fill='black')
-
- def dessin4():
- can.delete(ALL)
- can.create_rectangle(10,10,190,190,fill='grey90')
- can.create_oval(30,30,70,70,fill='black')
- can.create_oval(130,130,170,170,fill='black')
- can.create_oval(130,30,170,70,fill='black')
- can.create_oval(30,130,70,170,fill='black')
-
-
- def dessin5():
- can.delete(ALL)
- can.create_rectangle(10,10,190,190,fill='grey90')
- can.create_oval(80,80,120,120,fill='black')
- can.create_oval(30,30,70,70,fill='black')
- can.create_oval(130,130,170,170,fill='black')
- can.create_oval(130,30,170,70,fill='black')
- can.create_oval(30,130,70,170,fill='black')
-
- def dessin6():
- can.delete(ALL)
- can.create_rectangle(10,10,190,190,fill='grey90')
- can.create_oval(30,30,70,70,fill='black')
- can.create_oval(130,130,170,170,fill='black')
- can.create_oval(130,30,170,70,fill='black')
- can.create_oval(30,130,70,170,fill='black')
- can.create_oval(30,80,70,120,fill='black')
- can.create_oval(130,80,170,120,fill='black')
-
- def des1():
- can1.delete(ALL)
- can1.create_rectangle(10,10,190,190,fill='grey90')
- can1.create_oval(80,80,120,120,fill='black')
-
- def des2():
- can1.delete(ALL)
- can1.create_rectangle(10,10,190,190,fill='grey90')
- can1.create_oval(30,30,70,70,fill='black')
- can1.create_oval(130,130,170,170,fill='black')
-
- def des3():
- can1.delete(ALL)
- can1.create_rectangle(10,10,190,190,fill='grey90')
- can1.create_oval(80,80,120,120,fill='black')
- can1.create_oval(30,30,70,70,fill='black')
- can1.create_oval(130,130,170,170,fill='black')
-
- def des4():
- can1.delete(ALL)
- can1.create_rectangle(10,10,190,190,fill='grey90')
- can1.create_oval(30,30,70,70,fill='black')
- can1.create_oval(130,130,170,170,fill='black')
- can1.create_oval(130,30,170,70,fill='black')
- can1.create_oval(30,130,70,170,fill='black')
-
-
- def des5():
- can1.delete(ALL)
- can1.create_rectangle(10,10,190,190,fill='grey90')
- can1.create_oval(80,80,120,120,fill='black')
- can1.create_oval(30,30,70,70,fill='black')
- can1.create_oval(130,130,170,170,fill='black')
- can1.create_oval(130,30,170,70,fill='black')
- can1.create_oval(30,130,70,170,fill='black')
-
- def des6():
- can1.delete(ALL)
- can1.create_rectangle(10,10,190,190,fill='grey90')
- can1.create_oval(30,30,70,70,fill='black')
- can1.create_oval(130,130,170,170,fill='black')
- can1.create_oval(130,30,170,70,fill='black')
- can1.create_oval(30,130,70,170,fill='black')
- can1.create_oval(30,80,70,120,fill='black')
- can1.create_oval(130,80,170,120,fill='black')
-
-
- def detec():
- global ars,ar, coup, cou
- g=[2,2,40,80,100,2,2,500]
- a=randrange(6)+1
- b=randrange(6)+1
- det=randrange(8)
- ga=g[det]
- if a==1:
- dessin1()
- if a==2:
- dessin2()
- if a==3:
- dessin3()
- if a==4:
- dessin4()
- if a==5:
- dessin5()
- if a==6:
- dessin6()
- if b==1:
- des1()
- if b==2:
- des2()
- if b==3:
- des3()
- if b==4:
- des4()
- if b==5:
- des5()
- if b==6:
- des6()
- if a+b==7:
- ch1.configure(text='Vous avez gagnié : ' + str(ga) + ' €')
- cou=cou+1
- ar=ar+ga
- l2.configure(text='Coup(s) gagnant(s) : ' + str(cou))
- if ar<=0:
- l4.configure(text='Argent disponible : ' + str(ar) + ' €',fg='red')
- else:
- l4.configure(text='Argent disponible : ' + str(ar) + ' €',fg='black')
- else :
- ch1.configure(text='Vous avez perdu : ' + str(ga) + ' €')
- ars=ga+ars
- coup=coup+1
- l1.configure(text='Argent perdu : ' + str(ars) + ' €')
- l3.configure(text='Coup(s) perdant(s) : ' + str(coup))
- ch.configure(text='Le total des dés est : ' + str(a+b) + ' (' + str(a) + ' + ' + str(b) + ')')
-
-
- def lan1():
- global bn
- b1.configure(state=DISABLED)
- bn=bn+1
- if bn==3:
- b4.configure(state=NORMAL)
- detec()
- def lan2():
- global bn
- b2.configure(state=DISABLED)
- bn=bn+1
- if bn==3:
- b4.configure(state=NORMAL)
- detec()
- def lan3():
- global bn
- b3.configure(state=DISABLED)
- bn=bn+1
- if bn==3:
- b4.configure(state=NORMAL)
- detec()
-
- def acha():
- global bn,tk, ar
- b1.configure(state=NORMAL)
- b2.configure(state=NORMAL)
- b3.configure(state=NORMAL)
- b4.configure(state=DISABLED)
- bn=0
- tk=tk+1
- ar=ar-2
- l.configure(text='Nombre de ticket achetés : ' + str(tk))
- if ar<=0:
- l4.configure(text='Argent disponible : ' + str(ar) + ' €',fg='red')
- else:
- l4.configure(text='Argent disponible : ' + str(ar) + ' €',fg='black')
-
-
- def quiter():
- ansk=askyesno('Quitter',"Voulez-vous réellement quitter ?")
- if ansk:
- tkMessageBox.showinfo('Salut', 'À une prochaine fois peut-être')
- fen.destroy()
-
- def helpe():
- tkMessageBox.showinfo('Aide',"Régle du jeu :\n\nQuand vous gratez une case (ça s'appel un lancer)\nil y a deux dés qui apparessent. Si leur somme fait\n7, vous avez gagnié, sinon vous avez perdu ! Pour ce qui ne savent\npas compter, il ne doivent pas s'inquietter, l'ordinateur compte pour eux !\nPrix d'un billet : 2 €.\n\nCf un vrai biller de Dédé pour plus de précision")
-
-
-
- def savoir():
- tkMessageBox.showinfo("À propos de ...", "Logiciel ''Imitation de Dédé''\n\n_______________________\n\n\nLogiciel créé avec Python 2.4 par Aéra group.\nVersion 1.1 (Avec Pmw)")
-
-
-
-
- # ===== 3. Programme principale ===== #
-
-
-
-
- fen = Tk()
- fen.title('Jeu de Dédé')
-
- bn=0
- tk=1
- ar=2
- ars=0
- cou=0
- coup=0
-
- fen.protocol("WM_DELETE_WINDOW", quiter)
-
- menu = Menu(fen)
- fichier=Menu(menu,tearoff=0)
- aid=Menu(menu,tearoff=0)
- menu.add_cascade(label='Fichier',menu=fichier)
- fichier.add_command(label='Nouveau',command=nouv)
- fichier.add_separator()
- fichier.add_command(label='Quitter',command=quiter)
- menu.add_cascade(label='Aide',menu=aid)
- aid.add_command(label='Aide',command=helpe)
- aid.add_separator()
- aid.add_command(label='À propos de ...',command=savoir)
- fen.config(menu = menu)
-
-
- grou = Pmw.Group(fen, tag_text = 'Gratage')
- grou.grid(row=3,column=1)
- grou1 = Pmw.Group(fen, tag_text = 'Potre-feuille')
- grou1.grid(row=3,column=2)
-
- can = Canvas(fen,width = 200, height = 200)
- can.grid(row=0, column=1,padx = 25, pady = 10)
- can1 = Canvas(fen,width = 200, height = 200)
- can1.grid(row=0, column=2,padx = 25, pady = 10)
-
- b1 = Button(grou.interior(),text = 'Gratter le lancer 1',command = lan1)
- b1.grid(padx = 5, pady = 5)
- b2 = Button(grou.interior(),text = 'Gratter le lancer 2',command = lan2)
- b2.grid(padx = 5, pady = 5)
- b3 = Button(grou.interior(),text = 'Gratter le lancer 3',command = lan3)
- b3.grid(padx = 5, pady = 5)
-
- ch = Label(fen)
- ch.grid(row=1,columnspan=4)
- ch1 = Label(fen)
- ch1.grid(row=2,columnspan=4)
- b4 = Button(fen,text = 'Racheter un ticket',command = acha)
- b4.grid(row=4,columnspan=4,padx = 10, pady = 10)
- b4.configure(state=DISABLED)
-
- l=Label(grou1.interior(),text='Nombre de ticket acheté : ' + str(tk))
- l.grid()
- l1=Label(grou1.interior(),text='Argent perdu : ' + str(ars) + ' €')
- l1.grid()
- l2=Label(grou1.interior(),text='Coup(s) gagnant(s) : ' + str(cou))
- l2.grid()
- l3=Label(grou1.interior(),text='Coup(s) perdant(s) : ' + str(coup))
- l3.grid()
- l4=Label(grou1.interior(),text='Argent disponible : ' + str(ar) + ' €')
- l4.grid()
-
- # ===== 4. Démarage ===== #
-
-
- fen.mainloop()
-
-
-
- ###############################################################
- ###############################################################
- ###############################################################
- ###############################################################
- ###############################################################
- ###############################################################
- ### V E S I O N n ° 2 #############
- ###############################################################
- ###############################################################
- ###############################################################
- ###############################################################
- ###############################################################
- ###############################################################
-
- # -*- coding:Utf-8 -*-
-
- #################
- # Aéra group #
- # #
- # Imitation du #
- # jeu Dédé #
- # Version 1.2 #
- #################
-
-
- #---------------------- Créé le dimanche 20 août 2006 ----------------------#
- #-------------- Dernière mise à jour : le 20 août 2006 --------------#
-
-
- #======================== PROGRAMME PYTHON : ========================#
-
-
-
-
-
-
- # ===== 1. Importation ===== #
-
-
-
- from Tkinter import *
- from random import *
- from tkMessageBox import askyesno
- import tkMessageBox
-
-
-
- # ===== 2. Fonctions préliminaires ===== #
-
- def nouv():
- global bn, ar, ars, tk, cou, coup
- ans=askyesno('Nouvelle partie',"Voulez-vous réellement recommencer une nouvelle partie ? \nVotre progression actuelle sera perdu")
- if ans:
- can.delete(ALL)
- can1.delete(ALL)
- bn=0
- ar=2
- ars=0
- tk=1
- cou=0
- coup=0
- b1.configure(state=NORMAL)
- b2.configure(state=NORMAL)
- b3.configure(state=NORMAL)
- b4.configure(state=DISABLED)
- l.configure(text='Nombre de ticket acheté : ' + str(tk))
- l1.configure(text='Argent perdu : ' + str(ars) + ' €')
- l2.configure(text='Coup(s) gagnant(s) : ' + str(cou))
- l3.configure(text='Coup(s) perdant(s) : ' + str(coup))
- l4.configure(text='Argent disponible : ' + str(ar) + ' €',fg='black')
- ch.configure(text='')
- ch1.configure(text='')
-
-
-
- def dessin1():
- can.delete(ALL)
- can.create_rectangle(10,10,190,190,fill='grey90')
- can.create_oval(80,80,120,120,fill='black')
-
- def dessin2():
- can.delete(ALL)
- can.create_rectangle(10,10,190,190,fill='grey90')
- can.create_oval(30,30,70,70,fill='black')
- can.create_oval(130,130,170,170,fill='black')
-
- def dessin3():
- can.delete(ALL)
- can.create_rectangle(10,10,190,190,fill='grey90')
- can.create_oval(80,80,120,120,fill='black')
- can.create_oval(30,30,70,70,fill='black')
- can.create_oval(130,130,170,170,fill='black')
-
- def dessin4():
- can.delete(ALL)
- can.create_rectangle(10,10,190,190,fill='grey90')
- can.create_oval(30,30,70,70,fill='black')
- can.create_oval(130,130,170,170,fill='black')
- can.create_oval(130,30,170,70,fill='black')
- can.create_oval(30,130,70,170,fill='black')
-
-
- def dessin5():
- can.delete(ALL)
- can.create_rectangle(10,10,190,190,fill='grey90')
- can.create_oval(80,80,120,120,fill='black')
- can.create_oval(30,30,70,70,fill='black')
- can.create_oval(130,130,170,170,fill='black')
- can.create_oval(130,30,170,70,fill='black')
- can.create_oval(30,130,70,170,fill='black')
-
- def dessin6():
- can.delete(ALL)
- can.create_rectangle(10,10,190,190,fill='grey90')
- can.create_oval(30,30,70,70,fill='black')
- can.create_oval(130,130,170,170,fill='black')
- can.create_oval(130,30,170,70,fill='black')
- can.create_oval(30,130,70,170,fill='black')
- can.create_oval(30,80,70,120,fill='black')
- can.create_oval(130,80,170,120,fill='black')
-
- def des1():
- can1.delete(ALL)
- can1.create_rectangle(10,10,190,190,fill='grey90')
- can1.create_oval(80,80,120,120,fill='black')
-
- def des2():
- can1.delete(ALL)
- can1.create_rectangle(10,10,190,190,fill='grey90')
- can1.create_oval(30,30,70,70,fill='black')
- can1.create_oval(130,130,170,170,fill='black')
-
- def des3():
- can1.delete(ALL)
- can1.create_rectangle(10,10,190,190,fill='grey90')
- can1.create_oval(80,80,120,120,fill='black')
- can1.create_oval(30,30,70,70,fill='black')
- can1.create_oval(130,130,170,170,fill='black')
-
- def des4():
- can1.delete(ALL)
- can1.create_rectangle(10,10,190,190,fill='grey90')
- can1.create_oval(30,30,70,70,fill='black')
- can1.create_oval(130,130,170,170,fill='black')
- can1.create_oval(130,30,170,70,fill='black')
- can1.create_oval(30,130,70,170,fill='black')
-
-
- def des5():
- can1.delete(ALL)
- can1.create_rectangle(10,10,190,190,fill='grey90')
- can1.create_oval(80,80,120,120,fill='black')
- can1.create_oval(30,30,70,70,fill='black')
- can1.create_oval(130,130,170,170,fill='black')
- can1.create_oval(130,30,170,70,fill='black')
- can1.create_oval(30,130,70,170,fill='black')
-
- def des6():
- can1.delete(ALL)
- can1.create_rectangle(10,10,190,190,fill='grey90')
- can1.create_oval(30,30,70,70,fill='black')
- can1.create_oval(130,130,170,170,fill='black')
- can1.create_oval(130,30,170,70,fill='black')
- can1.create_oval(30,130,70,170,fill='black')
- can1.create_oval(30,80,70,120,fill='black')
- can1.create_oval(130,80,170,120,fill='black')
-
-
- def detec():
- global ars,ar, coup, cou
- g=[2,2,40,80,100,2,2,500]
- a=randrange(6)+1
- b=randrange(6)+1
- det=randrange(8)
- ga=g[det]
- if a==1:
- dessin1()
- if a==2:
- dessin2()
- if a==3:
- dessin3()
- if a==4:
- dessin4()
- if a==5:
- dessin5()
- if a==6:
- dessin6()
- if b==1:
- des1()
- if b==2:
- des2()
- if b==3:
- des3()
- if b==4:
- des4()
- if b==5:
- des5()
- if b==6:
- des6()
- if a+b==7:
- ch1.configure(text='Vous avez gagnié : ' + str(ga) + ' €')
- cou=cou+1
- ar=ar+ga
- l2.configure(text='Coup(s) gagnant(s) : ' + str(cou))
- if ar<=0:
- l4.configure(text='Argent disponible : ' + str(ar) + ' €',fg='red')
- else:
- l4.configure(text='Argent disponible : ' + str(ar) + ' €',fg='black')
- else :
- ch1.configure(text='Vous avez perdu : ' + str(ga) + ' €')
- ars=ga+ars
- coup=coup+1
- l1.configure(text='Argent perdu : ' + str(ars) + ' €')
- l3.configure(text='Coup(s) perdant(s) : ' + str(coup))
- ch.configure(text='Le total des dés est : ' + str(a+b) + ' (' + str(a) + ' + ' + str(b) + ')')
-
-
- def lan1():
- global bn
- b1.configure(state=DISABLED)
- bn=bn+1
- if bn==3:
- b4.configure(state=NORMAL)
- detec()
- def lan2():
- global bn
- b2.configure(state=DISABLED)
- bn=bn+1
- if bn==3:
- b4.configure(state=NORMAL)
- detec()
- def lan3():
- global bn
- b3.configure(state=DISABLED)
- bn=bn+1
- if bn==3:
- b4.configure(state=NORMAL)
- detec()
-
- def acha():
- global bn,tk, ar
- b1.configure(state=NORMAL)
- b2.configure(state=NORMAL)
- b3.configure(state=NORMAL)
- b4.configure(state=DISABLED)
- bn=0
- tk=tk+1
- ar=ar-2
- l.configure(text='Nombre de ticket achetés : ' + str(tk))
- if ar<=0:
- l4.configure(text='Argent disponible : ' + str(ar) + ' €',fg='red')
- else:
- l4.configure(text='Argent disponible : ' + str(ar) + ' €',fg='black')
-
-
- def quiter():
- ansk=askyesno('Quitter',"Voulez-vous réellement quitter ?")
- if ansk:
- tkMessageBox.showinfo('Salut', 'À une prochaine fois peut-être')
- fen.destroy()
-
- def helpe():
- tkMessageBox.showinfo('Aide',"Régle du jeu :\n\nQuand vous gratez une case (ça s'appel un lancer)\nil y a deux dés qui apparessent. Si leur somme fait\n7, vous avez gagnié, sinon vous avez perdu ! Pour ce qui ne savent\npas compter, il ne doivent pas s'inquietter, l'ordinateur compte pour eux !\nPrix d'un billet : 2 €.\n\nCf un vrai biller de Dédé pour plus de précision")
-
-
-
- def savoir():
- tkMessageBox.showinfo("À propos de ...", "Logiciel ''Imitation de Dédé''\n\n_______________________\n\n\nLogiciel créé avec Python 2.4 par Aéra group.\nVersion 1.2 (Sans Pmw)")
-
-
-
-
- # ===== 3. Programme principale ===== #
-
-
-
-
- fen = Tk()
- fen.title('Jeu de Dédé')
-
- bn=0
- tk=1
- ar=2
- ars=0
- cou=0
- coup=0
-
- fen.protocol("WM_DELETE_WINDOW", quiter)
-
- menu = Menu(fen)
- fichier=Menu(menu,tearoff=0)
- aid=Menu(menu,tearoff=0)
- menu.add_cascade(label='Fichier',menu=fichier)
- fichier.add_command(label='Nouveau',command=nouv)
- fichier.add_separator()
- fichier.add_command(label='Quitter',command=quiter)
- menu.add_cascade(label='Aide',menu=aid)
- aid.add_command(label='Aide',command=helpe)
- aid.add_separator()
- aid.add_command(label='À propos de ...',command=savoir)
- fen.config(menu = menu)
-
-
- grou = Frame(fen,bd =2, relief =RAISED)
- grou.grid(row=3,column=1)
- grou1 = Frame(fen,bd =2, relief =RAISED)
- grou1.grid(row=3,column=2)
-
- can = Canvas(fen,width = 200, height = 200)
- can.grid(row=0, column=1,padx = 25, pady = 10)
- can1 = Canvas(fen,width = 200, height = 200)
- can1.grid(row=0, column=2,padx = 25, pady = 10)
-
- b1 = Button(grou,text = 'Gratter le lancer 1',command = lan1)
- b1.grid(padx = 5, pady = 5)
- b2 = Button(grou,text = 'Gratter le lancer 2',command = lan2)
- b2.grid(padx = 5, pady = 5)
- b3 = Button(grou,text = 'Gratter le lancer 3',command = lan3)
- b3.grid(padx = 5, pady = 5)
-
- ch = Label(fen)
- ch.grid(row=1,columnspan=4)
- ch1 = Label(fen)
- ch1.grid(row=2,columnspan=4)
- b4 = Button(fen,text = 'Racheter un ticket',command = acha)
- b4.grid(row=4,columnspan=4,padx = 10, pady = 10)
- b4.configure(state=DISABLED)
-
- l=Label(grou1,text='Nombre de ticket acheté : ' + str(tk))
- l.grid()
- l1=Label(grou1,text='Argent perdu : ' + str(ars) + ' €')
- l1.grid()
- l2=Label(grou1,text='Coup(s) gagnant(s) : ' + str(cou))
- l2.grid()
- l3=Label(grou1,text='Coup(s) perdant(s) : ' + str(coup))
- l3.grid()
- l4=Label(grou1,text='Argent disponible : ' + str(ar) + ' €')
- l4.grid()
-
- # ===== 4. Démarage ===== #
-
-
- fen.mainloop()
# -*- coding:Utf-8 -*-
#################
# Aéra group #
# #
# Imitation du #
# jeu Dédé #
# Version 1.1 #
#################
#---------------------- Créé le dimanche 20 août 2006 ----------------------#
#-------------- Dernière mise à jour : le 20 août 2006 --------------#
#======================== PROGRAMME PYTHON : ========================#
# ===== 1. Importation ===== #
from Tkinter import *
import Pmw
from random import *
from tkMessageBox import askyesno
import tkMessageBox
# ===== 2. Fonctions préliminaires ===== #
def nouv():
global bn, ar, ars, tk, cou, coup
ans=askyesno('Nouvelle partie',"Voulez-vous réellement recommencer une nouvelle partie ? \nVotre progression actuelle sera perdu")
if ans:
can.delete(ALL)
can1.delete(ALL)
bn=0
ar=2
ars=0
tk=1
cou=0
coup=0
b1.configure(state=NORMAL)
b2.configure(state=NORMAL)
b3.configure(state=NORMAL)
b4.configure(state=DISABLED)
l.configure(text='Nombre de ticket acheté : ' + str(tk))
l1.configure(text='Argent perdu : ' + str(ars) + ' €')
l2.configure(text='Coup(s) gagnant(s) : ' + str(cou))
l3.configure(text='Coup(s) perdant(s) : ' + str(coup))
l4.configure(text='Argent disponible : ' + str(ar) + ' €',fg='black')
ch.configure(text='')
ch1.configure(text='')
def dessin1():
can.delete(ALL)
can.create_rectangle(10,10,190,190,fill='grey90')
can.create_oval(80,80,120,120,fill='black')
def dessin2():
can.delete(ALL)
can.create_rectangle(10,10,190,190,fill='grey90')
can.create_oval(30,30,70,70,fill='black')
can.create_oval(130,130,170,170,fill='black')
def dessin3():
can.delete(ALL)
can.create_rectangle(10,10,190,190,fill='grey90')
can.create_oval(80,80,120,120,fill='black')
can.create_oval(30,30,70,70,fill='black')
can.create_oval(130,130,170,170,fill='black')
def dessin4():
can.delete(ALL)
can.create_rectangle(10,10,190,190,fill='grey90')
can.create_oval(30,30,70,70,fill='black')
can.create_oval(130,130,170,170,fill='black')
can.create_oval(130,30,170,70,fill='black')
can.create_oval(30,130,70,170,fill='black')
def dessin5():
can.delete(ALL)
can.create_rectangle(10,10,190,190,fill='grey90')
can.create_oval(80,80,120,120,fill='black')
can.create_oval(30,30,70,70,fill='black')
can.create_oval(130,130,170,170,fill='black')
can.create_oval(130,30,170,70,fill='black')
can.create_oval(30,130,70,170,fill='black')
def dessin6():
can.delete(ALL)
can.create_rectangle(10,10,190,190,fill='grey90')
can.create_oval(30,30,70,70,fill='black')
can.create_oval(130,130,170,170,fill='black')
can.create_oval(130,30,170,70,fill='black')
can.create_oval(30,130,70,170,fill='black')
can.create_oval(30,80,70,120,fill='black')
can.create_oval(130,80,170,120,fill='black')
def des1():
can1.delete(ALL)
can1.create_rectangle(10,10,190,190,fill='grey90')
can1.create_oval(80,80,120,120,fill='black')
def des2():
can1.delete(ALL)
can1.create_rectangle(10,10,190,190,fill='grey90')
can1.create_oval(30,30,70,70,fill='black')
can1.create_oval(130,130,170,170,fill='black')
def des3():
can1.delete(ALL)
can1.create_rectangle(10,10,190,190,fill='grey90')
can1.create_oval(80,80,120,120,fill='black')
can1.create_oval(30,30,70,70,fill='black')
can1.create_oval(130,130,170,170,fill='black')
def des4():
can1.delete(ALL)
can1.create_rectangle(10,10,190,190,fill='grey90')
can1.create_oval(30,30,70,70,fill='black')
can1.create_oval(130,130,170,170,fill='black')
can1.create_oval(130,30,170,70,fill='black')
can1.create_oval(30,130,70,170,fill='black')
def des5():
can1.delete(ALL)
can1.create_rectangle(10,10,190,190,fill='grey90')
can1.create_oval(80,80,120,120,fill='black')
can1.create_oval(30,30,70,70,fill='black')
can1.create_oval(130,130,170,170,fill='black')
can1.create_oval(130,30,170,70,fill='black')
can1.create_oval(30,130,70,170,fill='black')
def des6():
can1.delete(ALL)
can1.create_rectangle(10,10,190,190,fill='grey90')
can1.create_oval(30,30,70,70,fill='black')
can1.create_oval(130,130,170,170,fill='black')
can1.create_oval(130,30,170,70,fill='black')
can1.create_oval(30,130,70,170,fill='black')
can1.create_oval(30,80,70,120,fill='black')
can1.create_oval(130,80,170,120,fill='black')
def detec():
global ars,ar, coup, cou
g=[2,2,40,80,100,2,2,500]
a=randrange(6)+1
b=randrange(6)+1
det=randrange(8)
ga=g[det]
if a==1:
dessin1()
if a==2:
dessin2()
if a==3:
dessin3()
if a==4:
dessin4()
if a==5:
dessin5()
if a==6:
dessin6()
if b==1:
des1()
if b==2:
des2()
if b==3:
des3()
if b==4:
des4()
if b==5:
des5()
if b==6:
des6()
if a+b==7:
ch1.configure(text='Vous avez gagnié : ' + str(ga) + ' €')
cou=cou+1
ar=ar+ga
l2.configure(text='Coup(s) gagnant(s) : ' + str(cou))
if ar<=0:
l4.configure(text='Argent disponible : ' + str(ar) + ' €',fg='red')
else:
l4.configure(text='Argent disponible : ' + str(ar) + ' €',fg='black')
else :
ch1.configure(text='Vous avez perdu : ' + str(ga) + ' €')
ars=ga+ars
coup=coup+1
l1.configure(text='Argent perdu : ' + str(ars) + ' €')
l3.configure(text='Coup(s) perdant(s) : ' + str(coup))
ch.configure(text='Le total des dés est : ' + str(a+b) + ' (' + str(a) + ' + ' + str(b) + ')')
def lan1():
global bn
b1.configure(state=DISABLED)
bn=bn+1
if bn==3:
b4.configure(state=NORMAL)
detec()
def lan2():
global bn
b2.configure(state=DISABLED)
bn=bn+1
if bn==3:
b4.configure(state=NORMAL)
detec()
def lan3():
global bn
b3.configure(state=DISABLED)
bn=bn+1
if bn==3:
b4.configure(state=NORMAL)
detec()
def acha():
global bn,tk, ar
b1.configure(state=NORMAL)
b2.configure(state=NORMAL)
b3.configure(state=NORMAL)
b4.configure(state=DISABLED)
bn=0
tk=tk+1
ar=ar-2
l.configure(text='Nombre de ticket achetés : ' + str(tk))
if ar<=0:
l4.configure(text='Argent disponible : ' + str(ar) + ' €',fg='red')
else:
l4.configure(text='Argent disponible : ' + str(ar) + ' €',fg='black')
def quiter():
ansk=askyesno('Quitter',"Voulez-vous réellement quitter ?")
if ansk:
tkMessageBox.showinfo('Salut', 'À une prochaine fois peut-être')
fen.destroy()
def helpe():
tkMessageBox.showinfo('Aide',"Régle du jeu :\n\nQuand vous gratez une case (ça s'appel un lancer)\nil y a deux dés qui apparessent. Si leur somme fait\n7, vous avez gagnié, sinon vous avez perdu ! Pour ce qui ne savent\npas compter, il ne doivent pas s'inquietter, l'ordinateur compte pour eux !\nPrix d'un billet : 2 €.\n\nCf un vrai biller de Dédé pour plus de précision")
def savoir():
tkMessageBox.showinfo("À propos de ...", "Logiciel ''Imitation de Dédé''\n\n_______________________\n\n\nLogiciel créé avec Python 2.4 par Aéra group.\nVersion 1.1 (Avec Pmw)")
# ===== 3. Programme principale ===== #
fen = Tk()
fen.title('Jeu de Dédé')
bn=0
tk=1
ar=2
ars=0
cou=0
coup=0
fen.protocol("WM_DELETE_WINDOW", quiter)
menu = Menu(fen)
fichier=Menu(menu,tearoff=0)
aid=Menu(menu,tearoff=0)
menu.add_cascade(label='Fichier',menu=fichier)
fichier.add_command(label='Nouveau',command=nouv)
fichier.add_separator()
fichier.add_command(label='Quitter',command=quiter)
menu.add_cascade(label='Aide',menu=aid)
aid.add_command(label='Aide',command=helpe)
aid.add_separator()
aid.add_command(label='À propos de ...',command=savoir)
fen.config(menu = menu)
grou = Pmw.Group(fen, tag_text = 'Gratage')
grou.grid(row=3,column=1)
grou1 = Pmw.Group(fen, tag_text = 'Potre-feuille')
grou1.grid(row=3,column=2)
can = Canvas(fen,width = 200, height = 200)
can.grid(row=0, column=1,padx = 25, pady = 10)
can1 = Canvas(fen,width = 200, height = 200)
can1.grid(row=0, column=2,padx = 25, pady = 10)
b1 = Button(grou.interior(),text = 'Gratter le lancer 1',command = lan1)
b1.grid(padx = 5, pady = 5)
b2 = Button(grou.interior(),text = 'Gratter le lancer 2',command = lan2)
b2.grid(padx = 5, pady = 5)
b3 = Button(grou.interior(),text = 'Gratter le lancer 3',command = lan3)
b3.grid(padx = 5, pady = 5)
ch = Label(fen)
ch.grid(row=1,columnspan=4)
ch1 = Label(fen)
ch1.grid(row=2,columnspan=4)
b4 = Button(fen,text = 'Racheter un ticket',command = acha)
b4.grid(row=4,columnspan=4,padx = 10, pady = 10)
b4.configure(state=DISABLED)
l=Label(grou1.interior(),text='Nombre de ticket acheté : ' + str(tk))
l.grid()
l1=Label(grou1.interior(),text='Argent perdu : ' + str(ars) + ' €')
l1.grid()
l2=Label(grou1.interior(),text='Coup(s) gagnant(s) : ' + str(cou))
l2.grid()
l3=Label(grou1.interior(),text='Coup(s) perdant(s) : ' + str(coup))
l3.grid()
l4=Label(grou1.interior(),text='Argent disponible : ' + str(ar) + ' €')
l4.grid()
# ===== 4. Démarage ===== #
fen.mainloop()
###############################################################
###############################################################
###############################################################
###############################################################
###############################################################
###############################################################
### V E S I O N n ° 2 #############
###############################################################
###############################################################
###############################################################
###############################################################
###############################################################
###############################################################
# -*- coding:Utf-8 -*-
#################
# Aéra group #
# #
# Imitation du #
# jeu Dédé #
# Version 1.2 #
#################
#---------------------- Créé le dimanche 20 août 2006 ----------------------#
#-------------- Dernière mise à jour : le 20 août 2006 --------------#
#======================== PROGRAMME PYTHON : ========================#
# ===== 1. Importation ===== #
from Tkinter import *
from random import *
from tkMessageBox import askyesno
import tkMessageBox
# ===== 2. Fonctions préliminaires ===== #
def nouv():
global bn, ar, ars, tk, cou, coup
ans=askyesno('Nouvelle partie',"Voulez-vous réellement recommencer une nouvelle partie ? \nVotre progression actuelle sera perdu")
if ans:
can.delete(ALL)
can1.delete(ALL)
bn=0
ar=2
ars=0
tk=1
cou=0
coup=0
b1.configure(state=NORMAL)
b2.configure(state=NORMAL)
b3.configure(state=NORMAL)
b4.configure(state=DISABLED)
l.configure(text='Nombre de ticket acheté : ' + str(tk))
l1.configure(text='Argent perdu : ' + str(ars) + ' €')
l2.configure(text='Coup(s) gagnant(s) : ' + str(cou))
l3.configure(text='Coup(s) perdant(s) : ' + str(coup))
l4.configure(text='Argent disponible : ' + str(ar) + ' €',fg='black')
ch.configure(text='')
ch1.configure(text='')
def dessin1():
can.delete(ALL)
can.create_rectangle(10,10,190,190,fill='grey90')
can.create_oval(80,80,120,120,fill='black')
def dessin2():
can.delete(ALL)
can.create_rectangle(10,10,190,190,fill='grey90')
can.create_oval(30,30,70,70,fill='black')
can.create_oval(130,130,170,170,fill='black')
def dessin3():
can.delete(ALL)
can.create_rectangle(10,10,190,190,fill='grey90')
can.create_oval(80,80,120,120,fill='black')
can.create_oval(30,30,70,70,fill='black')
can.create_oval(130,130,170,170,fill='black')
def dessin4():
can.delete(ALL)
can.create_rectangle(10,10,190,190,fill='grey90')
can.create_oval(30,30,70,70,fill='black')
can.create_oval(130,130,170,170,fill='black')
can.create_oval(130,30,170,70,fill='black')
can.create_oval(30,130,70,170,fill='black')
def dessin5():
can.delete(ALL)
can.create_rectangle(10,10,190,190,fill='grey90')
can.create_oval(80,80,120,120,fill='black')
can.create_oval(30,30,70,70,fill='black')
can.create_oval(130,130,170,170,fill='black')
can.create_oval(130,30,170,70,fill='black')
can.create_oval(30,130,70,170,fill='black')
def dessin6():
can.delete(ALL)
can.create_rectangle(10,10,190,190,fill='grey90')
can.create_oval(30,30,70,70,fill='black')
can.create_oval(130,130,170,170,fill='black')
can.create_oval(130,30,170,70,fill='black')
can.create_oval(30,130,70,170,fill='black')
can.create_oval(30,80,70,120,fill='black')
can.create_oval(130,80,170,120,fill='black')
def des1():
can1.delete(ALL)
can1.create_rectangle(10,10,190,190,fill='grey90')
can1.create_oval(80,80,120,120,fill='black')
def des2():
can1.delete(ALL)
can1.create_rectangle(10,10,190,190,fill='grey90')
can1.create_oval(30,30,70,70,fill='black')
can1.create_oval(130,130,170,170,fill='black')
def des3():
can1.delete(ALL)
can1.create_rectangle(10,10,190,190,fill='grey90')
can1.create_oval(80,80,120,120,fill='black')
can1.create_oval(30,30,70,70,fill='black')
can1.create_oval(130,130,170,170,fill='black')
def des4():
can1.delete(ALL)
can1.create_rectangle(10,10,190,190,fill='grey90')
can1.create_oval(30,30,70,70,fill='black')
can1.create_oval(130,130,170,170,fill='black')
can1.create_oval(130,30,170,70,fill='black')
can1.create_oval(30,130,70,170,fill='black')
def des5():
can1.delete(ALL)
can1.create_rectangle(10,10,190,190,fill='grey90')
can1.create_oval(80,80,120,120,fill='black')
can1.create_oval(30,30,70,70,fill='black')
can1.create_oval(130,130,170,170,fill='black')
can1.create_oval(130,30,170,70,fill='black')
can1.create_oval(30,130,70,170,fill='black')
def des6():
can1.delete(ALL)
can1.create_rectangle(10,10,190,190,fill='grey90')
can1.create_oval(30,30,70,70,fill='black')
can1.create_oval(130,130,170,170,fill='black')
can1.create_oval(130,30,170,70,fill='black')
can1.create_oval(30,130,70,170,fill='black')
can1.create_oval(30,80,70,120,fill='black')
can1.create_oval(130,80,170,120,fill='black')
def detec():
global ars,ar, coup, cou
g=[2,2,40,80,100,2,2,500]
a=randrange(6)+1
b=randrange(6)+1
det=randrange(8)
ga=g[det]
if a==1:
dessin1()
if a==2:
dessin2()
if a==3:
dessin3()
if a==4:
dessin4()
if a==5:
dessin5()
if a==6:
dessin6()
if b==1:
des1()
if b==2:
des2()
if b==3:
des3()
if b==4:
des4()
if b==5:
des5()
if b==6:
des6()
if a+b==7:
ch1.configure(text='Vous avez gagnié : ' + str(ga) + ' €')
cou=cou+1
ar=ar+ga
l2.configure(text='Coup(s) gagnant(s) : ' + str(cou))
if ar<=0:
l4.configure(text='Argent disponible : ' + str(ar) + ' €',fg='red')
else:
l4.configure(text='Argent disponible : ' + str(ar) + ' €',fg='black')
else :
ch1.configure(text='Vous avez perdu : ' + str(ga) + ' €')
ars=ga+ars
coup=coup+1
l1.configure(text='Argent perdu : ' + str(ars) + ' €')
l3.configure(text='Coup(s) perdant(s) : ' + str(coup))
ch.configure(text='Le total des dés est : ' + str(a+b) + ' (' + str(a) + ' + ' + str(b) + ')')
def lan1():
global bn
b1.configure(state=DISABLED)
bn=bn+1
if bn==3:
b4.configure(state=NORMAL)
detec()
def lan2():
global bn
b2.configure(state=DISABLED)
bn=bn+1
if bn==3:
b4.configure(state=NORMAL)
detec()
def lan3():
global bn
b3.configure(state=DISABLED)
bn=bn+1
if bn==3:
b4.configure(state=NORMAL)
detec()
def acha():
global bn,tk, ar
b1.configure(state=NORMAL)
b2.configure(state=NORMAL)
b3.configure(state=NORMAL)
b4.configure(state=DISABLED)
bn=0
tk=tk+1
ar=ar-2
l.configure(text='Nombre de ticket achetés : ' + str(tk))
if ar<=0:
l4.configure(text='Argent disponible : ' + str(ar) + ' €',fg='red')
else:
l4.configure(text='Argent disponible : ' + str(ar) + ' €',fg='black')
def quiter():
ansk=askyesno('Quitter',"Voulez-vous réellement quitter ?")
if ansk:
tkMessageBox.showinfo('Salut', 'À une prochaine fois peut-être')
fen.destroy()
def helpe():
tkMessageBox.showinfo('Aide',"Régle du jeu :\n\nQuand vous gratez une case (ça s'appel un lancer)\nil y a deux dés qui apparessent. Si leur somme fait\n7, vous avez gagnié, sinon vous avez perdu ! Pour ce qui ne savent\npas compter, il ne doivent pas s'inquietter, l'ordinateur compte pour eux !\nPrix d'un billet : 2 €.\n\nCf un vrai biller de Dédé pour plus de précision")
def savoir():
tkMessageBox.showinfo("À propos de ...", "Logiciel ''Imitation de Dédé''\n\n_______________________\n\n\nLogiciel créé avec Python 2.4 par Aéra group.\nVersion 1.2 (Sans Pmw)")
# ===== 3. Programme principale ===== #
fen = Tk()
fen.title('Jeu de Dédé')
bn=0
tk=1
ar=2
ars=0
cou=0
coup=0
fen.protocol("WM_DELETE_WINDOW", quiter)
menu = Menu(fen)
fichier=Menu(menu,tearoff=0)
aid=Menu(menu,tearoff=0)
menu.add_cascade(label='Fichier',menu=fichier)
fichier.add_command(label='Nouveau',command=nouv)
fichier.add_separator()
fichier.add_command(label='Quitter',command=quiter)
menu.add_cascade(label='Aide',menu=aid)
aid.add_command(label='Aide',command=helpe)
aid.add_separator()
aid.add_command(label='À propos de ...',command=savoir)
fen.config(menu = menu)
grou = Frame(fen,bd =2, relief =RAISED)
grou.grid(row=3,column=1)
grou1 = Frame(fen,bd =2, relief =RAISED)
grou1.grid(row=3,column=2)
can = Canvas(fen,width = 200, height = 200)
can.grid(row=0, column=1,padx = 25, pady = 10)
can1 = Canvas(fen,width = 200, height = 200)
can1.grid(row=0, column=2,padx = 25, pady = 10)
b1 = Button(grou,text = 'Gratter le lancer 1',command = lan1)
b1.grid(padx = 5, pady = 5)
b2 = Button(grou,text = 'Gratter le lancer 2',command = lan2)
b2.grid(padx = 5, pady = 5)
b3 = Button(grou,text = 'Gratter le lancer 3',command = lan3)
b3.grid(padx = 5, pady = 5)
ch = Label(fen)
ch.grid(row=1,columnspan=4)
ch1 = Label(fen)
ch1.grid(row=2,columnspan=4)
b4 = Button(fen,text = 'Racheter un ticket',command = acha)
b4.grid(row=4,columnspan=4,padx = 10, pady = 10)
b4.configure(state=DISABLED)
l=Label(grou1,text='Nombre de ticket acheté : ' + str(tk))
l.grid()
l1=Label(grou1,text='Argent perdu : ' + str(ars) + ' €')
l1.grid()
l2=Label(grou1,text='Coup(s) gagnant(s) : ' + str(cou))
l2.grid()
l3=Label(grou1,text='Coup(s) perdant(s) : ' + str(coup))
l3.grid()
l4=Label(grou1,text='Argent disponible : ' + str(ar) + ' €')
l4.grid()
# ===== 4. Démarage ===== #
fen.mainloop()
Conclusion
Voilà. À noté que d'abitude, je fais une version avec WxPython. Ici, exeptionellement je n'en ai pas fait, faute de temps. Peu être dans un certain temps, j'en crérais une , mais rien n'ai sûr.
NOTE AUX PERSONNES QUI SOUHAITE TÉLÉCHARGER LA BLIBLIOTHÈQUE GRAPHIQUE PMW :
Il est possible de télécharger la bibliotèque
sur le site http://prdownloads.sourceforge.net/pmw/Pmw.1.2.tar .gz?download. Vous obtiendrez un fichier
compresser que vous décompresserez dans "C:\Python24\Lib\site-packages" (si "C:\Python24" est votre répertoire
d'instalation de Python 2.4 (ou autre version bien entendu))
Sources du même auteur
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
IMAGINE CUP 2012, MAKE A SIGN EN FINALEIMAGINE CUP 2012, MAKE A SIGN EN FINALE par junarnoalg
Voilà qui est fait, la nouvelle est officielle ! L'équipe belge "Make a Sign" va au pays des kangourous défendre son projet dans la catégorie Software Design. http://www.imaginecup.com/CompetitionsContent/Competition/WorldwideFinalists.aspx V...
Cliquez pour lire la suite de l'article par junarnoalg KINECT 1.5 IS OUT !KINECT 1.5 IS OUT ! par Vko
La version 1.5 du Kinect For Microsoft vient tout juste de sortir ! Plein de nouveautés: Tracking de squelette en Near Mode Détection en position assise Détection faciale avec un SDK dédié Documentation et des guideline (enfin) Un out...
Cliquez pour lire la suite de l'article par Vko LES ACTUALITéS DE LA SEMAINE SUR C2I.FR (14 MAI - 20 MAI) LES ACTUALITéS DE LA SEMAINE SUR C2I.FR (14 MAI - 20 MAI) par richardc
Mise à jour des Web API du 14 Mai
Réservez dès maintenant votre journée du 20 juin pour le Windows Azure Dev Camp 2012 à Paris
Mise à jour de Team Foundation Service
MechCommander 2 sur Windows 8
Entity Framework 5 Release Candidate e...
Cliquez pour lire la suite de l'article par richardc REACTIVE EXTENSIONS : CONSOMMER DES SERVICES AVEC RX PARTIE 3, LES PIèGES à éVITERREACTIVE EXTENSIONS : CONSOMMER DES SERVICES AVEC RX PARTIE 3, LES PIèGES à éVITER par Groc
Une mauvaise utilisation de rx lors de l'écriture d'une couche d'accès à des services peut conduire à des cas embarassants avec des erreurs mal gérées, des appels qui ne partent lorsqu'ils le devraient, et même des résultats incorrects . le tout nuis...
Cliquez pour lire la suite de l'article par Groc SHAREPOINT BLOG SITE, PROBLèME D'ARCHIVESSHAREPOINT BLOG SITE, PROBLèME D'ARCHIVES par junarnoalg
Dernièrement, nous avons migré le site
myTIC
vers un nouveau serveur SharePoint 2010. Dans les contenus que nous vouloins récupérer, nous avions un certain nombre de blogs.
Nous avons utilisé les commandes Power...
Cliquez pour lire la suite de l'article par junarnoalg
Logiciels
974 Application Server (12.2.4.0)974 APPLICATION SERVER (12.2.4.0)Développez de puissantes applications dans un environnement de 'cloud computing', clusterisé, séc... Cliquez pour télécharger 974 Application Server vPicture (1.4.2.1)VPICTURE (1.4.2.1)Avec vPicture, hébergez vos images facilement et rapidement.
vPicture est un utilitaire simple, ... Cliquez pour télécharger vPicture Easy-Planning (2.2.1.6)EASY-PLANNING (2.2.1.6)Easy-Planning permet de créer des plannings sous la représentation de diagrammes et est adapté au... Cliquez pour télécharger Easy-Planning COM-BACKUP (2.0)COM-BACKUP (2.0)
COM-BACKUP est un logiciel de sauvegarde qui permet de planifier les sauvegardes de vos dossiers ...
Cliquez pour télécharger COM-BACKUP mySongBook Player (1.0.0)MYSONGBOOK PLAYER (1.0.0)mySongBook Player est un logiciel gratuit permettant l'accès à une archive de tablatures/partitio... Cliquez pour télécharger mySongBook Player
|