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
| from tkinter import *
from random import *
from PIL import Image
#Importation de l'image
File = "Image.png"
Im = Image.open(File)
#Convertion de l'image en .gif
Im.save("Im.gif")
#Création des carrés de 50x50 pixels
Liste1 = []
for m in range(7):
<div style="margin-left:40px">for n in range(7):</div><div style="margin-left:40px"><div style="margin-left:40px">Liste1.append((50*n, 50*m))</div></div>
#Création des 49 carrés de 50x50 pixels
Liste2 = []
for o in range(49):
<div style="margin-left:40px">Liste2.append(o)</div>
#Création d'une fenêtre
Fen = Tk()
Fen.title("LOTO Game")
Fen.geometry("500x545")
Fen.configure(bg="black")
#Création d'un label "Veuillez choisir une couleur"
Lab1 = Label(Fen, text="Veuillez choisir une couleur :", width=24, height=2, bg="white")
Lab1.place(x=160, y=20)
#Création d'une entry "Gagné/Perdu"
Saisir = StringVar()
Saisie = Entry(Fen, textvariable=Saisir, width=10)
Saisie.place(x=50, y=500)
#Création des couleurs
Gris = "#%02x%02x%02x" % (100, 100, 100)
Rouge = "#%02x%02x%02x" % (255, 25, 25)
Bleu = "#%02x%02x%02x" % (50, 100, 255)
Jaune = "#%02x%02x%02x" % (225, 225, 25)
#Bouton gris
def numero1():
<div style="margin-left:40px">global Test</div><div style="margin-left:40px">for n in range(1):</div><div style="margin-left:40px">Choice = choice(Liste2)</div><div style="margin-left:40px">k = Liste1[Choice][0]</div><div style="margin-left:40px">l = Liste1[Choice][1]</div><div style="margin-left:40px">Get = Im.getpixel(Liste1[Choice])</div><div style="margin-left:40px">#Gris</div><div style="margin-left:40px">if Get==(100,100,100):</div><div style="margin-left:40px"><div style="margin-left:40px">for i in range(50):</div></div><div style="margin-left:40px"><div style="margin-left:40px"><div style="margin-left:40px">for j in range(50):</div></div></div><div style="margin-left:40px"><div style="margin-left:40px"><div style="margin-left:40px"><div style="margin-left:40px">Im.putpixel((k+i,l+j),(75,75,75))</div></div></div></div><div style="margin-left:40px">#Rouge</div><div style="margin-left:40px">elif Get==(255,25,25):</div><div style="margin-left:40px"><div style="margin-left:40px">for i in range(50):</div></div><div style="margin-left:40px"><div style="margin-left:40px"><div style="margin-left:40px">for j in range(50):</div></div></div><div style="margin-left:40px"><div style="margin-left:40px"><div style="margin-left:40px"><div style="margin-left:40px">Im.putpixel((k+i,l+j),(230,0,0))</div></div></div></div><div style="margin-left:40px">#Bleu</div><div style="margin-left:40px">elif Get==(50,100,255):</div><div style="margin-left:40px"><div style="margin-left:40px">for i in range(50):</div></div><div style="margin-left:40px"><div style="margin-left:40px"><div style="margin-left:40px">for j in range(50):</div></div></div><div style="margin-left:40px"><div style="margin-left:40px"><div style="margin-left:40px"><div style="margin-left:40px">Im.putpixel((k+i,l+j),(25,75,230))</div></div></div></div><div style="margin-left:40px">#Jaune</div><div style="margin-left:40px">else:</div><div style="margin-left:40px"><div style="margin-left:40px">for i in range(50):</div></div><div style="margin-left:40px"><div style="margin-left:40px"><div style="margin-left:40px">for j in range(50):</div></div></div><div style="margin-left:40px"><div style="margin-left:40px"><div style="margin-left:40px"><div style="margin-left:40px">Im.putpixel((k+i,l+j),(200,200,0))</div></div></div></div>
<div style="margin-left:40px">Im.show()</div>
#Bouton rouge
def numero2():
<div style="margin-left:40px">global Test</div><div style="margin-left:40px">Canv2 = Canvas(Fen, height=348, width=348, bg=Rouge)</div><div style="margin-left:40px">Canv2.place(x=75, y=75)</div>
#Bouton bleu
def numero3():
<div style="margin-left:40px">global Test</div><div style="margin-left:40px">Canv3 = Canvas(Fen, height=348, width=348, bg=Bleu)</div><div style="margin-left:40px">Canv3.place(x=75, y=75)</div>
#Bouton jaune
def numero4():
<div style="margin-left:40px">global Test</div><div style="margin-left:40px">Canv4 = Canvas(Fen, height=348, width=348, bg=Jaune)</div><div style="margin-left:40px">Canv4.place(x=75, y=75)</div>
#Bouton rejouer
def numero5():
<div style="margin-left:40px">global Test</div><div style="margin-left:40px">Canvr = Canvas(Fen, height=348, width=348, bg="Orange")</div><div style="margin-left:40px">Canvr.place(x=75, y=75)</div>
#Création du bouton gris
Bou1 = Button(Fen, text=" ", command=numero1, bg=Gris)
Bou1.place(x=50, y=450)
#Création du bouton rouge
Bou2 = Button(Fen, text=" ", command=numero2, bg=Rouge)
Bou2.place(x=135, y=450)
#Création du bouton bleu
Bou3 = Button(Fen, text=" ", command=numero3, bg=Bleu)
Bou3.place(x=220, y=450)
#Création du bouton jaune
Bou4 = Button(Fen, text=" ", command=numero4, bg=Jaune)
Bou4.place(x=305, y=450)
#Création du bouton quitter
Bouq = Button(Fen, text=" Quitter ", command=Fen.destroy)
Bouq.place(x=400, y=450)
#Création du bouton rejouer
Bour = Button(Fen, text=" Rejouer ", command=numero5, bg="white")
Bour.place(x=400, y=500)
Canv = Canvas(Fen, height=348, width=348)
Canv.place(x=75, y=75)
Image = PhotoImage(file="Im.gif")
Canv.create_image(175, 175, image=Image)
Fen.mainloop() |
Partager