Probleme liaison interface tkinter et programme

Fermé
Rilex Messages postés 7 Date d'inscription vendredi 4 mai 2018 Statut Membre Dernière intervention 13 mai 2018 - Modifié le 13 mai 2018 à 19:52
yg_be Messages postés 22697 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 18 avril 2024 - 14 mai 2018 à 20:00
Bonjour,
J'ai besion d'aide j'ai realiser une interface graphique pas finit mais presque et un programme j'aimerais bien lié les deux mais lorsque que je fait ceci mon interface crash.Je ne sais pas pourquoi.Mon progrogramme est la fonction programme sinon le reste est l'interface graphique.Il faut savoir que le programme marche si le code est indépendant de de celui de l'interface.
lorsque j'appuie sur le bouton match le programme du match de tennis se lance tout seul dans le shell alors que normalement il devrait s'activer lors de la pression sur le boutton .Et ceci peut expliquer pourquoi mon interface ne repond plus et n'affiche pas la fenetre top. J'aimerais savoir comment faire pour qu'il s'active que lorsque il y a une pression sur le boutton start.





from tkinter import *
def sourisevent(evt):
print("1")
def sourisevent2(evt):
print("2")
def programmme():
joueur1=1
joueur2=2
score=[0,15,30,40,"jeu"]
ex=[40,"adv","jeu"]
score1=score[0]
score2=score[0]
point1=0
point2=0
set1=0
set2=0
jeu1=0
jeu2=0
tie1=0
tie2=0
while set1!=3 and set2!=3:
while (jeu1-jeu2<=1 or jeu1<=5) and (jeu2-jeu1<=1 or jeu2<=5) :
while score1!="jeu" and score2!="jeu":
vainqueur=input("qui a marque?")
if score1==40 and score2==40:
if vainqueur=="1":
score1="adv"
else:
score2="adv"
elif score1==40 and score2=="adv":
if vainqueur=="2":
score1=40
score2="jeu"
elif vainqueur=="1":
score1=40
score2=40
elif score1=="adv" and score2==40 :
if vainqueur=="1":
score1="jeu"
score2=40
elif vainqueur=="2":
score1=40
score2=40
elif vainqueur=="1":
point1=point1+1
score1=score[point1]
else:
point2=point2+1
score2=score[point2]
print("point:",score1,score2)
if score1=="jeu":
jeu1=jeu1+1
elif score2=="jeu":
jeu2=jeu2+1
if jeu1>5 and jeu1-jeu2>1 :
set1=set1+1
elif jeu2>5 and jeu2-jeu1>1 :
set2=set2+1
if jeu1==6 and jeu2==6 :
print("Tie-break")
while (tie1-tie2<=1 or tie1<=6) and (tie2-tie1<=1 or tie2<=6):
gagnant=int(input("qui a marque?"))
if gagnant==1:
tie1=tie1+1
else:
tie2=tie2+1
print("Tie-break:",tie1,tie2)
if tie1-tie2>=2 and tie1>6 :
set1=set1+1
jeu1=0
jeu2=0
tie1=0
tie2=0
elif tie2-tie1>=2 and tie2>6 :
set2=set2+1
jeu2=0
jeu1=0
tie1=0
tie2=0
print("jeu",jeu1,jeu2)
print("set:",set1,set2)
score1=0
score2=0
point1=0
point2=0
jeu1=0
jeu2=0
if set1==3:
print("Joueur1 a gagné")
if set2==3:
print("Joueur2 a gagné")

def pl():
top=Toplevel(fenetre,background="grey")
top.title('MATCH')
top.geometry("1280x720")

Frame1 = Frame(top, borderwidth=2,relief=GROOVE,bg="blue")
Frame1.pack(side=TOP, padx=20, pady=20)
Label(Frame1, text="J1",font="Arial 40",bg="blue").pack(padx=20, pady=20)
Frame1.place(x=50,y=100)

Frame2 = Frame(top, borderwidth=2,relief=GROOVE,bg="orange")
Frame2.pack(side=TOP, padx=20, pady=20)
Label(Frame2, text="J1",font="Arial 40",bg="orange").pack(padx=20, pady=20)
Frame2.place(x=50,y=450)

Frame3 = Frame(top, borderwidth=2,relief=GROOVE)
Frame3.pack(side=TOP, padx=15, pady=15)
Label(Frame3, text="POINTS",font="Arial 30").pack(padx=15, pady=250)
Frame3.place(x=200,y=50)

top.bind('<KeyPress-1>', sourisevent)
top.bind('<KeyPress-2>', sourisevent2)


Frame4 = Frame(top, borderwidth=2,relief=GROOVE)
Frame4.pack(side=TOP, padx=15, pady=15)
Label(Frame4, text="SET 1",font="Arial 30").pack(padx=15, pady=250)
Frame4.place(x=500,y=50)

Frame5 = Frame(top, borderwidth=2,relief=GROOVE)
Frame5.pack(side=TOP, padx=15, pady=15)
Label(Frame5, text="SET 2",font="Arial 30").pack(padx=15, pady=250)
Frame5.place(x=800,y=50)


Frame6 = Frame(top, borderwidth=2,relief=GROOVE)
Frame6.pack(side=TOP, padx=15, pady=15)
Label(Frame6, text="SET 3",font="Arial 30").pack(padx=15, pady=250)
Frame6.place(x=1100,y=50)
quitter2 =Button(top, text="Quitter",font="Arial 30", command=top.destroy,
background="#DD151A",activebackground="#B2161A",foreground="white",overrelief="groove")
quitter2.place(x=650, y=630)
start =Button(top, text="start",font="Arial 30",background="green",activebackground="green",command=programmme(),foreground="white",overrelief="groove")
start.place(x=50, y=630)





fenetre = Tk()
fenetre.title('afficheur de score de tennis')
fenetre.geometry("1280x720")

Image_fond = PhotoImage(file="tenniswallpaper.gif")
image= Canvas(fenetre)
image.pack(fill=BOTH, expand=1)
image.create_image(0,0, image=Image_fond,anchor=NW)


mode1 =Button(fenetre,text="MATCH",command=pl,font="Verdana 30",background="#7d7f91", activebackground="#7d7f91", foreground="white",
width=20, height=2, overrelief="groove")
mode1.place(x=400,y=200)



quitter =Button(fenetre, text="Quitter",font="Arial 30", command=fenetre.destroy,
background="#DD151A",activebackground="#B2161A",foreground="white",overrelief="groove")
quitter.place(x=550, y=468)


fenetre.mainloop()

1 réponse

yg_be Messages postés 22697 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 18 avril 2024 1 471
13 mai 2018 à 21:07
bonsoir,
merci d'utiliser la coloration syntaxique pour poster du code, surtout du code python.
0
Rilex Messages postés 7 Date d'inscription vendredi 4 mai 2018 Statut Membre Dernière intervention 13 mai 2018
13 mai 2018 à 22:16
Ha,oui excusez moi j'avais oublié.

from tkinter import *
def sourisevent(evt): 
print("1")
def sourisevent2(evt): 
print("2")
def programmme():
joueur1=1
joueur2=2
score=[0,15,30,40,"jeu"]
ex=[40,"adv","jeu"]
score1=score[0]
score2=score[0]
point1=0
point2=0
set1=0
set2=0
jeu1=0
jeu2=0
tie1=0
tie2=0
while set1!=3 and set2!=3:
while (jeu1-jeu2<=1 or jeu1<=5) and (jeu2-jeu1<=1 or jeu2<=5) :
while score1!="jeu" and score2!="jeu":
vainqueur=input("qui a marque?")
if score1==40 and score2==40:
if vainqueur=="1":
score1="adv"
else:
score2="adv"
elif score1==40 and score2=="adv":
if vainqueur=="2":
score1=40
score2="jeu"
elif vainqueur=="1":
score1=40
score2=40
elif score1=="adv" and score2==40 :
if vainqueur=="1":
score1="jeu"
score2=40
elif vainqueur=="2":
score1=40
score2=40
elif vainqueur=="1":
point1=point1+1
score1=score[point1]
else:
point2=point2+1
score2=score[point2]
print("point:",score1,score2)
if score1=="jeu":
jeu1=jeu1+1
elif score2=="jeu":
jeu2=jeu2+1
if jeu1>5 and jeu1-jeu2>1 :
set1=set1+1
elif jeu2>5 and jeu2-jeu1>1 :
set2=set2+1
if jeu1==6 and jeu2==6 :
print("Tie-break")
while (tie1-tie2<=1 or tie1<=6) and (tie2-tie1<=1 or tie2<=6):
gagnant=int(input("qui a marque?"))
if gagnant==1:
tie1=tie1+1
else:
tie2=tie2+1
print("Tie-break:",tie1,tie2)
if tie1-tie2>=2 and tie1>6 :
set1=set1+1
jeu1=0
jeu2=0
tie1=0
tie2=0
elif tie2-tie1>=2 and tie2>6 :
set2=set2+1
jeu2=0
jeu1=0
tie1=0
tie2=0
print("jeu",jeu1,jeu2)
print("set:",set1,set2)
score1=0
score2=0
point1=0
point2=0
jeu1=0
jeu2=0
if set1==3:
print("Joueur1 a gagné")
if set2==3:
print("Joueur2 a gagné")

def pl():
top=Toplevel(fenetre,background="grey")
top.title('MATCH')
top.geometry("1280x720")

Frame1 = Frame(top, borderwidth=2,relief=GROOVE,bg="blue")
Frame1.pack(side=TOP, padx=20, pady=20)
Label(Frame1, text="J1",font="Arial 40",bg="blue").pack(padx=20, pady=20)
Frame1.place(x=50,y=100)

Frame2 = Frame(top, borderwidth=2,relief=GROOVE,bg="orange")
Frame2.pack(side=TOP, padx=20, pady=20)
Label(Frame2, text="J2",font="Arial 40",bg="orange").pack(padx=20, pady=20)
Frame2.place(x=50,y=450)

Frame3 = Frame(top, borderwidth=2,relief=GROOVE)
Frame3.pack(side=TOP, padx=15, pady=15)
Label(Frame3, text="POINTS",font="Arial 30").pack(padx=15, pady=250)
Frame3.place(x=200,y=50)

top.bind('<KeyPress-1>', sourisevent)
top.bind('<KeyPress-2>', sourisevent2)


Frame4 = Frame(top, borderwidth=2,relief=GROOVE)
Frame4.pack(side=TOP, padx=15, pady=15)
Label(Frame4, text="SET 1",font="Arial 30").pack(padx=15, pady=250)
Frame4.place(x=500,y=50)

Frame5 = Frame(top, borderwidth=2,relief=GROOVE)
Frame5.pack(side=TOP, padx=15, pady=15)
Label(Frame5, text="SET 2",font="Arial 30").pack(padx=15, pady=250)
Frame5.place(x=800,y=50)


Frame6 = Frame(top, borderwidth=2,relief=GROOVE)
Frame6.pack(side=TOP, padx=15, pady=15)
Label(Frame6, text="SET 3",font="Arial 30").pack(padx=15, pady=250)
Frame6.place(x=1100,y=50)
quitter2 =Button(top, text="Quitter",font="Arial 30", command=top.destroy,
background="#DD151A",activebackground="#B2161A",foreground="white",overrelief="groove")
quitter2.place(x=650, y=630)
start =Button(top, text="start",font="Arial 30",background="green",activebackground="green",command=programmme(),foreground="white",overrelief="groove")
start.place(x=50, y=630)





fenetre = Tk()
fenetre.title('afficheur de score de tennis')
fenetre.geometry("1280x720")

Image_fond = PhotoImage(file="tenniswallpaper.gif")
image= Canvas(fenetre)
image.pack(fill=BOTH, expand=1)
image.create_image(0,0, image=Image_fond,anchor=NW)


mode1 =Button(fenetre,text="MATCH",command=pl,font="Verdana 30",background="#7d7f91", activebackground="#7d7f91", foreground="white",
width=20, height=2, overrelief="groove")
mode1.place(x=400,y=200)



quitter =Button(fenetre, text="Quitter",font="Arial 30", command=fenetre.destroy,
background="#DD151A",activebackground="#B2161A",foreground="white",overrelief="groove")
quitter.place(x=550, y=468)


fenetre.mainloop()
<code python>
0
yg_be Messages postés 22697 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 18 avril 2024 1 471 > Rilex Messages postés 7 Date d'inscription vendredi 4 mai 2018 Statut Membre Dernière intervention 13 mai 2018
14 mai 2018 à 20:00
je ne vois pas l'indentation...
0