samedi 10 juin 2017

My test for a Tkinter Checkbutton does not work

I'm working on a small project and I would like to be able to use a check button to pause the game. The problem is I do not manage to get the button state, although how to proceed is pretty well documented on the Internet. I do not know where I am doing wrong.

Here is my code (sorry for words in french) :

#Gestion de la fenêtre et de ses composants

xRes = 600;
yRes = 600;


Fenetre=Tk();
Fenetre.title('Fourmi');


Canevas = Canvas(Fenetre, width = xRes, height =yRes)
Canevas.pack(padx =0, pady =0);

defaut = StringVar(Fenetre);#Permet de définir une valeur par défaut
w = Scale(Fenetre, from_=1, to=20, orient=HORIZONTAL);#Choix de la vitesse
w.set(10);
w.pack();

pause = Checkbutton(Fenetre, text="Pause");
pause.pack();

grille=tableau(); #Crée une instance "grille" de la classe "tableau"

xSize = (xRes/grille.largeur);
ySize = (yRes/grille.hauteur);

grille.generer();
f=fourmi();#Crée une instance "f" de la classe "fourmi"

#_______________________________________________________________________________________________________________________________________



#Opérations répétées à chaque itération

while f.xPos < grille.largeur and f.yPos < grille.hauteur and f.xPos > 0 and f.yPos > 0:


    if pause.state(['!selected']):
        vitesse=float(w.get());
        f.seDeplacer(grille);
        f.afficher();
        sleep(1/(vitesse*10));

    Canevas.bind('<Button-3>', grille.changerCouleur);#Si clic droit, changer couleur case. Attention : Cette fonction retourne un argument contenant la position de la souris à la fonction


#________________________________________________________________________________________________________________________________________

Could you help me to fix that. Thank you anyway.




Aucun commentaire:

Enregistrer un commentaire