IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Tkinter Python Discussion :

je ne comprends comment marche l'Instruction BUTTON()


Sujet :

Tkinter Python

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Novembre 2007
    Messages
    5
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2007
    Messages : 5
    Par défaut je ne comprends comment marche l'Instruction BUTTON()
    Bonjour, je début en python et je ne comprends pas pourquoi quand je déclare des boutons, le programme passe et exécute chaque commande de chacun de mes boutons au départ et non quand je clic dessus?
    voici mon proragmme
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    from Tkinter import *
    # définition des gestionnaires
    # d'événements :
     
    def start_it():
        print 'début de l animation'
        global flag
        global no
        print 'flag av',flag
        flag =1
        print 'flag ap',flag
     
    def num(no) :
        print 'num flag av',flag
        if flag == 1 :       
            cpt[no]=0
            nbf[no]=nbf[no]+1
            txt1 = Label(fen1, text = cpt[no])
            txt2 = Label(fen1, text = nbf[no])
            txt1.grid(row =1,column=no)
            txt2.grid(row =2,column=no)
            t = range(36)
            print 'num',no
            for a in t:
                if a <> no:
                    cpt[a]=cpt[a]+1
                    txt1 = Label(fen1, text = cpt[a])
                    txt2 = Label(fen1, text = nbf[a])
                    txt1.grid(row =1,column=a)
                    txt2.grid(row =2,column=a)
     
        elif flag == 0 :
            txt1 = Label(fen1, text = cpt[no])
            txt2 = Label(fen1, text = nbf[no])
            txt1.grid(row =1,column=no)
            txt2.grid(row =2,column=no)
     
    #========== Programme principal =============
     
    # les variables suivantes seront utilisées de manière globale :
    flag = 0
    cpt =[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
    nbf =[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
    # Création du widget principal ("parent") :
    fen1 = Tk()
    fen1.title("ecart roulette")
     
    bouq = Button(fen1,text='Quit', width =4,command=fen1.quit)
    bouq.grid(row =4,column =3)
     
    bou0 = Button(fen1, text='0', width =4, command = num(0))
    bou0.grid(row =0,column =0)
    bou1 = Button(fen1, text='1', width =4, command=num(1) )
    bou1.grid(row =0,column =1)
    bou2 = Button(fen1, text='2', width =4, command=num(2))
    bou2.grid(row =0,column =2)
    bou3 = Button(fen1, text='3', width =4, command=num(3))
    bou3.grid(row =0,column =3)
    bou4 = Button(fen1, text='4', width =4, command=num(4))
    bou4.grid(row =0,column =4)
    bou5 = Button(fen1, text='5', width =4, command=num(5))
    bou5.grid(row =0,column =5)
    bou6 = Button(fen1, text='6', width =4, command=num(6))
    bou6.grid(row =0,column =6)
    bou7 = Button(fen1, text='7', width =4, command=num(7))
    bou7.grid(row =0,column =7)
    bou8 = Button(fen1, text='8', width =4, command=num(8))
    bou8.grid(row =0,column =8)
    bou9 = Button(fen1, text='9', width =4, command=num(9))
    bou9.grid(row =0,column =9)
     
    bou10 = Button(fen1, text='10', width =4, command=num(10))
    bou10.grid(row =0,column =10)
    bou11 = Button(fen1, text='11', width =4, command=num(11))
    bou11.grid(row =0,column =11)
    bou12 = Button(fen1, text='12', width =4, command=num(12))
    bou12.grid(row =0,column =12)
    bou13 = Button(fen1, text='13', width =4, command=num(13))
    bou13.grid(row =0,column =13)
    bou14 = Button(fen1, text='14', width =4, command=num(14))
    bou14.grid(row =0,column =14)
    bou15 = Button(fen1, text='15', width =4, command=num(15))
    bou15.grid(row =0,column =15)
    bou16 = Button(fen1, text='16', width =4, command=num(16))
    bou16.grid(row =0,column =16)
    bou17 = Button(fen1, text='17', width =4, command=num(17))
    bou17.grid(row =0,column =17)
    bou18 = Button(fen1, text='18', width =4, command=num(18))
    bou18.grid(row =0,column =18)
    bou19 = Button(fen1, text='19', width =4, command=num(19))
    bou19.grid(row =0,column =19)
     
    bou20 = Button(fen1, text='20', width =4, command=num(20))
    bou20.grid(row =0,column =20)
    bou21 = Button(fen1, text='21', width =4, command=num(21))
    bou21.grid(row =0,column =21)
    bou22 = Button(fen1, text='22', width =4, command=num(22))
    bou22.grid(row =0,column =22)
    bou23 = Button(fen1, text='23', width =4, command=num(23))
    bou23.grid(row =0,column =23)
    bou24 = Button(fen1, text='24', width =4, command=num(24))
    bou24.grid(row =0,column =24)
    bou25 = Button(fen1, text='25', width =4, command=num(25))
    bou25.grid(row =0,column =25)
    bou26 = Button(fen1, text='26', width =4, command=num(26))
    bou26.grid(row =0,column =26)
    bou27 = Button(fen1, text='27', width =4, command=num(27))
    bou27.grid(row =0,column =27)
    bou28 = Button(fen1, text='28', width =4, command=num(28))
    bou28.grid(row =0,column =28)
    bou29 = Button(fen1, text='29', width =4, command=num(29))
    bou29.grid(row =0,column =29)
     
    bou30 = Button(fen1, text='30', width =4, command=num(30))
    bou30.grid(row =0,column =30)
    bou31 = Button(fen1, text='31', width =4, command=num(31))
    bou31.grid(row =0,column =31)
    bou32 = Button(fen1, text='32', width =4, command=num(32))
    bou32.grid(row =0,column =32)
    bou33 = Button(fen1, text='33', width =4, command=num(33))
    bou33.grid(row =0,column =33)
    bou34 = Button(fen1, text='34', width =4, command=num(34))
    bou34.grid(row =0,column =34)
    bou35 = Button(fen1, text='35', width =4, command=num(35))
    bou35.grid(row =0,column =35)
    bou36 = Button(fen1, text='36', width =4, command=num(36))
    bou36.grid(row =0,column =36)
     
    bour = Button(fen1, text='debu', width =4, command=start_it())
    bour.grid(row =4,column =1)
     
    bous = Button(fen1, text='save', width =4, )
    bous.grid(row =4,column =2)
     
     
    fen1.mainloop() # démarrage du réceptionnaire d'événements
    fen1.destroy() # destruction (fermeture) de la fenêtre

  2. #2
    Expert confirmé
    Avatar de Guigui_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Août 2002
    Messages
    1 864
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Saône et Loire (Bourgogne)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Enseignement

    Informations forums :
    Inscription : Août 2002
    Messages : 1 864

  3. #3
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Novembre 2007
    Messages
    5
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2007
    Messages : 5
    Par défaut encore un grand merci !!
    ça fait deux jours que je chercher

  4. #4
    Membre confirmé
    Inscrit en
    Octobre 2007
    Messages
    32
    Détails du profil
    Informations forums :
    Inscription : Octobre 2007
    Messages : 32
    Par défaut
    si tu veux passer des parametre dans la fonction que dois déclencher ton bouton, il faut passer par une instruction "lambda".

    fais une recherche sur le forum, le sujet a déjà été traité.

    ++

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [C#] Comment exécuter une instruction dynamiquement ?
    Par NeoMan dans le forum Contribuez
    Réponses: 11
    Dernier message: 15/01/2009, 16h45
  2. comment marche fftw???
    Par aider une débutante dans le forum Bibliothèques
    Réponses: 3
    Dernier message: 11/11/2007, 10h33
  3. Comment utiliser des instructions SSE2 dans un code c++?
    Par alexIsBack dans le forum x86 32-bits / 64-bits
    Réponses: 7
    Dernier message: 22/02/2006, 19h10
  4. Comment marche un union ?
    Par Fredri dans le forum Access
    Réponses: 4
    Dernier message: 10/01/2006, 17h46
  5. Comment marche GlutSwapBuffers() ?
    Par Sloughidog dans le forum OpenGL
    Réponses: 2
    Dernier message: 29/09/2002, 14h45

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo