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 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
| import tkinter
from tkinter import Tk, Entry, Menu, PhotoImage, Label, Frame, LabelFrame, Canvas, Listbox, Button, Image, messagebox, Toplevel
from PIL import ImageTk, Image
import json
global ticks
ticks = 0
liste_voiture = ["Aston Martin Vantage GT3", "McLaren 720S GT3", "Dodge Viper GTS R", "Alfa Romeo 33/3 1972", "Alfa Romeo 33/3 1971" ]
liste_portrait = [ "Satanas panthère", "Folle du volant", "Sorcière sans balai", "Vieux à donf'"]
liste_portrait_photo = ["portrait_5", "portrait_6", "portrait_8", "portrait_7"]
#def configurer():
#saisie = Tk()
#pilote = Entry(saisie)
#saisie.mainloop()
def quitter():
quit()
def config():
global pilote1, pilote2, voiture1, voiture2, temps_course, portrait_pilote1, portrait_pilote2
if pilote1.get() =="" or pilote2.get() == "":
messagebox.showerror("Configuration incorrecte", "Vous devez nommer les pilotes.")
return
course = {}
fic = open('course.txt', 'w')
course['Pilote 1'] = pilote1.get()
course['Pilote 2'] = pilote2.get()
n = voiture1.curselection()[0]
course['Voiture 1'] = liste_voiture[n]
m = voiture2.curselection()[0]
course['Voiture 2'] = liste_voiture[m]
if course['Voiture 1'] == course['Voiture 2']:
messagebox.showerror("Configuration incorrecte", "Vous devez choisir des voitures différentes.")
return
o = portrait_pilote1.curselection()[0]
course['Portrait pilote 1'] = liste_portrait_photo[o]
p = portrait_pilote2.curselection()[0]
course['Portrait pilote 2'] = liste_portrait_photo[p]
course['Temps de course'] = int(temps_course.get())
with open("configcourse.json", "w") as fic:
json.dump(course, fic)
fic.close()
fenetre_ppale = Tk()
fenetre_ppale.geometry("1720x1080+10+10")
fenetre_ppale.title("Data Slot Course V1")
# GESTION DES IMAGES
image1 = Image.open("images/alpha_romeo.png")
image2 = Image.open("images/flag.png")
fond = ImageTk.PhotoImage(image1)
drapo = ImageTk.PhotoImage(image2)
#GESTON DES LISTES
list_v = tkinter.Variable(value=liste_voiture)
list_p = tkinter.Variable(value=liste_portrait)
# GESTION CONFIGURATION
def configurer():
global portrait_pilote1, portrait_pilote2, portrait_1, portrait_2, portrait_3, portrait_4, pilote1, pilote2, voiture1, voiture2, temps_course, frame3, frame4
#frame3, frame4
#GESTION DES IMAGES
dessin1 = Image.open("images/portrait_satanas.png")
dessin2 = Image.open("images/portrait_folle.png")
dessin3 = Image.open("images/portrait_sorciere.png")
dessin4 = Image.open("images/portrait_vieux.png")
portrait_1 = ImageTk.PhotoImage(dessin1)
portrait_2 = ImageTk.PhotoImage(dessin2)
portrait_3 = ImageTk.PhotoImage(dessin3)
portrait_4 = ImageTk.PhotoImage(dessin4)
# CARACTERISTIQUE DE LA FENETRE PRINCIPALE
fenetre_ppale.title("Configuration d'une course")
lbl_image.place_forget()
# FORMULAIRE
frame3 = Frame(fenetre_ppale, border=3, pady=0, padx=0, bg="whitesmoke")
frame3.place(x=100, y=100, relwidth=0.5, relheight=0.7)
#NOM DU PILOTE 1
label_pilote1 = Label(frame3, text = "PILOTE 1", font="Futura 24", bg="whitesmoke")
label_pilote1.place(x=25, y=28)
pilote1 = Entry(frame3, )
pilote1.place(x=25, y=65)
# NOM DU PILOTE 2
label_pilote2 = Label(frame3, text="PILOTE 2", font="Futura 24", bg="whitesmoke")
label_pilote2.place(x=500, y=28)
pilote2 = Entry(frame3, )
pilote2.place(x=500, y=65)
# VOITURE DU PILOTE 1
label_voiture1 = Label(frame3, text="VOITURE 1", font="Futura 24", bg="whitesmoke")
label_voiture1.place(x=25, y=110)
voiture1 = Listbox(frame3, listvariable=list_v, selectmode="SINGLE", exportselection=0, border=0, bg="whitesmoke")
voiture1.place(x=25, y=150)
# VOITURE DU PILOTE 2
label_voiture2 = Label(frame3, text="VOITURE 2", font="Futura 24", bg="whitesmoke")
label_voiture2.place(x=500, y=110)
voiture2 = Listbox(frame3, listvariable=list_v, selectmode="SINGLE", exportselection=0, border=0, bg="whitesmoke")
voiture2.place(x=500, y=150, )
# PORTTRAIT DU PILOTE 1
label_portrait1 = Label(frame3, text="PORTRAIT 1", font="Futura 24", bg="whitesmoke")
label_portrait1.place(x=25, y=260)
portrait_pilote1 = Listbox(frame3, listvariable=list_p, selectmode="SINGLE", exportselection=0, border=0, bg="whitesmoke")
portrait_pilote1.place(x=25, y=300)
# PORTTRAIT DU PILOTE 2
label_portrait2 = Label(frame3, text="PORTRAIT 2", font="Futura 24", bg="whitesmoke")
label_portrait2.place(x=500, y=260)
portrait_pilote2 = Listbox(frame3, listvariable=list_p, selectmode="SINGLE", exportselection=0, border=0, bg="whitesmoke")
portrait_pilote2.place(x=500, y=300)
# TEMPS DE COURSE
label_temps_course = Label(frame3, text="TEMPS COURSE", font="Futura 24", bg="whitesmoke")
label_temps_course.place(x=250, y=400)
temps_course = Entry(frame3, )
temps_course.place(x=250, y=450)
# CHOIX DES PORTRAITS
frame4 = Frame(fenetre_ppale, border=3, pady=0, padx=0, bg="whitesmoke")
frame4.place(x=950, y=100, relwidth=0.35, relheight=0.7)
satanas = Label(frame4, text="Satanas panthère", image=portrait_1, compound="top", border="0")
satanas.place(x=20, y=20)
folle = Label(frame4, text="Folle du volant", image=portrait_2, compound="top")
folle.place(x=20, y=280)
sorciere = Label(frame4, text="Sorcière sans balai", image=portrait_3, compound="top")
sorciere.place(x=260, y=20)
vieux = Label(frame4, text="Vieux à donf'", image=portrait_4, compound="top")
vieux.place(x=260, y=280)
# VALIDATION DES INFOS DE COURSE
validation = Button(frame3, text="VALIDER", font="Futura 18", bg="whitesmoke", fg="green", highlightcolor="red", command=config, border="0")
validation.place(x=240, y=520)
validation = Button(frame3, text="ANNULER", font="Futura 18", bg="whitesmoke", fg="red", highlightcolor="red", command=configurer, border="0")
validation.place(x=350, y=520)
# FONCTION CHRONOMETRE
def chrono():
global temps, ticks, nw, fenetre_ppale2
ticks += 1
minutes, secondes = divmod(ticks, 1000)
heures, minutes = divmod(minutes, 60)
temps_format = "{:02d}:{:02d}:{:02d}".format(heures, minutes, secondes)
temps.set(temps_format)
fenetre_ppale2.after(1, chrono)
def lancer():
global frame3, frame4, portrait_1, portrait_2, portrait_3, portrait_4, frame1, fenetre_ppale2
fenetre_ppale.destroy()
fenetre_ppale2 = Tk()
fenetre_ppale2.geometry("1720x1080+10+10")
# GESTION DES IMAGES
#image1 = Image.open("images/alpha_romeo.png")
image2 = Image.open("images/flag.png")
#fond = ImageTk.PhotoImage(image1)
drapo = ImageTk.PhotoImage(image2)
# INITIALISATION DESIMAGES
dessin1 = Image.open("images/portrait_satanas.png")
dessin2 = Image.open("images/portrait_folle.png")
dessin3 = Image.open("images/portrait_sorciere.png")
dessin4 = Image.open("images/portrait_vieux.png")
portrait_1 = ImageTk.PhotoImage(dessin1)
portrait_2 = ImageTk.PhotoImage(dessin2)
portrait_3 = ImageTk.PhotoImage(dessin3)
portrait_4 = ImageTk.PhotoImage(dessin4)
#frame3.place_forget()
#frame4.place_forget()
frame0 = Frame(fenetre_ppale2, border=0, pady=0, padx=0, bg="whitesmoke")
frame0.place(x=0, y=0, relwidth=1, height=120)
cnvg = Canvas(frame0, width=600, height=100, bg="whitesmoke")
cnvg.place(x=0, y=0)
cnvg.create_image(0, 0, image=drapo, anchor="nw")
cnvd = Canvas(frame0, width=600, height=100, bg="whitesmoke")
cnvd.place(x=1100, y=0)
cnvd.create_image(0, 0, image=drapo, anchor="nw")
# LABEL DU CHRONO
global temps, ticks
temps = tkinter.StringVar()
ticks = 0
temps.set("00:00:000")
label_temps = Label(frame0, textvariable=temps, font=("Futura", 36), bg="whitesmoke")
label_temps.place(x=750, y=0)
fenetre_ppale2.after(10, chrono)
chrono()
# RECUPERATION DES DONNEES DE LA COURSE
with open('configcourse.json', 'r') as fic:
data = json.load(fic)
# PILOTE 1
frame1 = Frame(fenetre_ppale2, width=573, height=800, bg="brown", pady=10, padx=10)
frame1.place(x=191, y=121)
lbl_frame1 = Label(frame1, text=data['Pilote 1'], font="Futura 42 bold", padx=20, bg="brown", fg="white")
lbl_frame1.place(relx=0.5, y=50, anchor="center")
#cnvh = Canvas(frame1, width=100, height=100, bg="whitesmoke")
#cnvh.place(x=20, y=100)
# cnvh.create_image(master="frame1", x=0, y=0, image=data['Portrait pilote 1'], anchor="center")
portrait_pilote_1 = Label(frame1, image=data["Portrait pilote 1"], compound="top", border="0")
portrait_pilote_1.place(master=frame1, relx=0.5, y=120, anchor="center")
# PILOTE 2
frame2 = Frame(fenetre_ppale2, width=573, height=800, bg="navy", pady=10, padx=10)
frame2.place(x=955, y=121)
lbl_frame2 = Label(frame2, text=data['Pilote 2'], font="Futura 42 bold", padx=20, bg="navy", fg="white")
lbl_frame2.place(relx=0.5, y=50, anchor="center")
fenetre_ppale2.mainloop()
# MENU PRINCIPAL
mon_menu = Menu(fenetre_ppale)
fichier_menu = Menu(mon_menu)
fichier_menu.add_command(label="configurer", command=configurer)
fichier_menu.add_command(label="Lancer", command=lancer)
fichier_menu.add_command(label="Quitter", command=quitter)
mon_menu.add_cascade(label="Fichier", menu=fichier_menu)
# IMAGE DE LANCEMENT
#img = PhotoImage(file="alpha_romeo.png")
lbl_image = Label(fenetre_ppale, image=fond)
lbl_image.place(x=0, y=0, relwidth=1, relheight=1)
fenetre_ppale.config(menu=mon_menu, bg="whitesmoke")
fenetre_ppale.mainloop() |
Partager