Bonjour,je crée actuellement un mastermind en python dans le cadre d'un projet. Je voudrais savoir si il est possible de changer la couleur du fond d'écran de ma fenêtre tkinter, et si il est possible de créer des bouton rond
Je vous laisse mon code:
# -*- coding: cp1252 -*-
from Tkinter import *
import random
fen=Tk()
fen.geometry("590x430+500-300")
fram=Frame(fen,height=500,width=450)
fram.grid()
def mastermind():
global ligneCourante,billeCourante,combiOrdi
ligneCourante,billeCourante=0,0
combiOrdi=detOrdi(couleur)
numLigne[ligneCourante].configure(text=str(ligneCourante+1))
resultat[ligneCourante].configure(text="Cliquez sur une couleur pour commencer.",font=("Comic sans ms",11))
def testerChoix(essai):
global ligneCourante,billeCourante
boutonOk[ligneCourante].configure(state=DISABLED)
boutonEffacer[ligneCourante].configure(state=DISABLED)
if testCombi(combiOrdi,essai)==True:
resultat[ligneCourante].configure(text="Bravo !! Victoire en "+str(ligneCourante+1)+" coups !")
elif ligneCourante==11:
resultat[ligneCourante].configure(text="Perdu !")
for i in range(4):
ligneSolution.itemconfigure(billeSolution[i],fill=combiOrdi[i])
else:
approx=detApprox(combiOrdi,essai)
resultat[ligneCourante].configure(text=str(approx[0])+" bien placée(s), "+str(approx[1])+" mal placée(s)",font=("comic sans ms",10))
ligneCourante+=1
billeCourante=0
numLigne[ligneCourante].configure(text=ligneCourante+1)
def detOrdi(couleur):
combiAleatoire=[""]*4
for i in range(4):
combiAleatoire[i]=couleur[random.randint(0,7)]
return combiAleatoire
def testCombi(combiOrdi,listeRes):
return listeRes==combiOrdi
def detApprox(combiOrdi,listeRes):
lRes,cOrdi,bP,mP=[""]*4,[""]*4,0,0
for i in range(4):
lRes[i]=listeRes[i]
cOrdi[i]=combiOrdi[i]
for i in range(4):
if lRes[i]==cOrdi[i] and lRes[i]!="":
bP+=1
cOrdi[i]=""
lRes[i]=""
for i in range(4):
for x in range(4):
if lRes[i]!="" and lRes[i]==cOrdi[x]:
mP+=1
cOrdi[x]=""
lRes[i]=""
break
return [bP,mP]
def effacerLigne():
global billeCourante
boutonOk[ligneCourante].configure(state=DISABLED)
if billeCourante==1:
boutonEffacer[ligneCourante].configure(state=DISABLED)
billeCourante-=1
ligne[ligneCourante].itemconfigure(bille[ligneCourante][billeCourante],fill="grey")
def changeCouleur(i):
global billeCourante
if billeCourante<4:
ligne[ligneCourante].itemconfigure(bille[ligneCourante][billeCourante],fill=couleur[i])
essai[billeCourante]=couleur[i]
billeCourante+=1
boutonEffacer[ligneCourante].configure(state=ACTIVE)
if billeCourante==4:
boutonOk[ligneCourante].configure(state=ACTIVE)
def quitter():
fram.quit()
fram.destroy()
def rejouer():
boutonOk[ligneCourante].configure(state=DISABLED)
boutonEffacer[ligneCourante].configure(state=DISABLED)
for i in range(4):
ligneSolution.itemconfigure(billeSolution[i],fill="grey")
for i in range(12):
resultat[i].configure(text="")
numLigne[i].configure(text="")
for x in range(4):
ligne[i].itemconfigure(bille[i][x],fill="grey")
mastermind()
couleur=["black","red","blue","yellow","green","orange","pink","purple"]
ligneCourante,billeCourante=0,0
ligneCourante=Label(fram,font="bold",fg="gold",width=40)
essai=[""]*4
ligne=[""]*12
bille=[[""]*4]*12
boutonOk=[""]*12
boutonEffacer=[""]*12
Solution=[""]*12
numLigne=[""]*12
resultat=[""]*12
i,t=1,1
while i<=12:
numLigne[i-1]=Label(fram,text="",fg="red",width=2)
numLigne[i-1].grid(row=i,column=1)
ligne[i-1]=Canvas(fram,bg="white",height=20,width=76)
ligne[i-1].grid(row=i,column=2)
x0,y0,x1,y1=3,3,20,20
w=0
while t<=i*4:
bille[i-1][w]=ligne[i-1].create_oval(x0,y0,x1,y1,fill="grey")
x0+=19
x1+=19
t+=1
w+=1
boutonEffacer[i-1]=Button(fram,text="--",command=effacerLigne,state=DISABLED)
boutonEffacer[i-1].grid(row=i,column=3)
boutonOk[i-1]=Button(fram,text="Ok",command=lambda arg=essai: testerChoix(arg),state=DISABLED)
boutonOk[i-1].grid(row=i,column=4)
resultat[i-1]=Label(fram,font="bold",fg="brown",width=48)
resultat[i-1].grid(row=i,columnspan=8,column=5)
i+=1
ligneSolution=Canvas(fram,bg="DimGrey",height=20,width=76)
ligneSolution.grid(row=14,column=2)
billeSolution=[""]*4
x0,y0,x1,y1=3,3,20,20
for i in range(4):
billeSolution[i]=ligneSolution.create_oval(x0,y0,x1,y1,fill="grey19")
x0+=19
x1+=19
boutonCouleur=[""]*8
for i in range(8):
boutonCouleur[i]=Button(fram,bg=couleur[i],height=1,width=2,command=lambda arg=i: changeCouleur(arg))
boutonCouleur[i].grid(row=15,column=5+i)
boutonRond=Canvas
boutonQuitter=Button(fram,text="Quitter",command=quitter,)
boutonQuitter.grid(row=15,columnspan=2,column=1)
boutonRejouer=Button(fram,text="Rejouer",command=rejouer,)
boutonRejouer.grid(row=14,columnspan=2,column=3)
mastermind()
fen.mainloop()
fen.destroy()
Merci de votre compréhension et de votre aide