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 :

nombre de clic de souris limités à environ 266 fois


Sujet :

Tkinter Python

  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 lenteur à l'execution ?
    Bonjour, je trouve l'execution demon programme de plus en plus lente !!
    peut on compiler du python ?

  2. #2
    Membre confirmé
    Inscrit en
    Octobre 2007
    Messages
    32
    Détails du profil
    Informations forums :
    Inscription : Octobre 2007
    Messages : 32
    Par défaut
    oui, vois la faq!

  3. #3
    Membre expérimenté
    Profil pro
    Étudiant
    Inscrit en
    Avril 2007
    Messages
    181
    Détails du profil
    Informations personnelles :
    Âge : 37
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2007
    Messages : 181
    Par défaut
    La FAQ parle d'optimiser Python en l'interfaçant avec du code C pour les calculs les plus demandeurs en temps processeur, ce qui n'est pas vraiment en rapport avec la question posée.

    @biokeops : j'ai déjà vu des applications écrites en Python vraiment grosses, sans que ces dernières soient lentes à l'exécution.
    Quelle est l'ampleur de ton projet ? Commence par isoler la portion du code qui fait ralentir toute ton application, et vois s'il y a des optimisations à faire dessus, poste le code qui pose problème, etc.

  4. #4
    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 nombre de clic de souris limités à environ 266 fois
    j'ai créer un prg pour compter la sortie de numéro de 0 à 36.
    chaque bouton représente un chiffre surlequel on clic et ainsi à chaque clic sur un chiffre, son compteur passe à zero et les autres compteur des autres chiffres on rajoute un.
    Le problème c'est qu'au environ 266 ème clic, le programme se bloque, plus de remise à zero et l'ajout de un à chaque chiffre ne se fait plus!!

    d'où cela provient-il ?

    voici mon prg :

    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
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    from Tkinter import *
    # définition des gestionnaires
    # d'événements :
     
    def reto() :
        global cpt,nbf,nob,nobcont
       # print 'reto nobcont',nobcont
       # print 'reto nob',nob
        cpt[nob]=nobcont
        #nbf[no]=nbf[no]+1
        txt1 = Label(fen1, text = cpt[nob])
       # txt2 = Label(fen1, text = nbf[no])
        txt1.grid(row =1,column=nob)
        #txt2.grid(row =2,column=no)
        t = range(37)
        for a in t:
            if a <> nob:
                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)
     
    def num(no) :
        global cpt,nbf,nob,nobcont
        print 'num cpt',cpt
        nob=no
        # print 'num nob',nob
        nobcont =cpt[no]
        # print 'num nobcont',nobcont
        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(37)
        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)
     
     
    #========== Programme principal =============
     
    # les variables suivantes seront utilisées de manière globale :
    no,npb =0,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("compteur")
    print 'cpt',cpt
    bouq = Button(fen1,text='Quit', width =4,command=fen1.quit)
    bouq.grid(row =4,column =3)
     
    bou0 = Button(fen1, text='0', width =4, command = lambda :num(0))
    bou0.grid(row =0,column =0)
    txt1 = Label(fen1, text = cpt[0])
    #txt2 = Label(fen1, text = nbf[0])
    txt1.grid(row =1,column=0)
    #txt2.grid(row =2,column=0)
    bou1 = Button(fen1, text='1', width =4, command=lambda :num(1) )
    bou1.grid(row =0,column =1)
    bou2 = Button(fen1, text='2', width =4, command=lambda :num(2))
    bou2.grid(row =0,column =2)
    bou3 = Button(fen1, text='3', width =4, command=lambda :num(3))
    bou3.grid(row =0,column =3)
    bou4 = Button(fen1, text='4', width =4, command=lambda :num(4))
    bou4.grid(row =0,column =4)
    bou5 = Button(fen1, text='5', width =4, command=lambda :num(5))
    bou5.grid(row =0,column =5)
    bou6 = Button(fen1, text='6', width =4, command=lambda :num(6))
    bou6.grid(row =0,column =6)
    bou7 = Button(fen1, text='7', width =4, command=lambda :num(7))
    bou7.grid(row =0,column =7)
    bou8 = Button(fen1, text='8', width =4, command=lambda :num(8))
    bou8.grid(row =0,column =8)
    bou9 = Button(fen1, text='9', width =4, command=lambda :num(9))
    bou9.grid(row =0,column =9)
     
    bou10 = Button(fen1, text='10', width =4, command=lambda :num(10))
    bou10.grid(row =0,column =10)
    bou11 = Button(fen1, text='11', width =4, command=lambda :num(11))
    bou11.grid(row =0,column =11)
    bou12 = Button(fen1, text='12', width =4, command=lambda :num(12))
    bou12.grid(row =0,column =12)
    bou13 = Button(fen1, text='13', width =4, command=lambda :num(13))
    bou13.grid(row =0,column =13)
    bou14 = Button(fen1, text='14', width =4, command=lambda :num(14))
    bou14.grid(row =0,column =14)
    bou15 = Button(fen1, text='15', width =4, command=lambda :num(15))
    bou15.grid(row =0,column =15)
    bou16 = Button(fen1, text='16', width =4, command=lambda :num(16))
    bou16.grid(row =0,column =16)
    bou17 = Button(fen1, text='17', width =4, command=lambda :num(17))
    bou17.grid(row =0,column =17)
    bou18 = Button(fen1, text='18', width =4, command=lambda :num(18))
    bou18.grid(row =0,column =18)
    bou19 = Button(fen1, text='19', width =4, command=lambda :num(19))
    bou19.grid(row =0,column =19)
     
    bou20 = Button(fen1, text='20', width =4, command=lambda :num(20))
    bou20.grid(row =0,column =20)
    bou21 = Button(fen1, text='21', width =4, command=lambda :num(21))
    bou21.grid(row =0,column =21)
    bou22 = Button(fen1, text='22', width =4, command=lambda :num(22))
    bou22.grid(row =0,column =22)
    bou23 = Button(fen1, text='23', width =4, command=lambda :num(23))
    bou23.grid(row =0,column =23)
    bou24 = Button(fen1, text='24', width =4, command=lambda :num(24))
    bou24.grid(row =0,column =24)
    bou25 = Button(fen1, text='25', width =4, command=lambda :num(25))
    bou25.grid(row =0,column =25)
    bou26 = Button(fen1, text='26', width =4, command=lambda :num(26))
    bou26.grid(row =0,column =26)
    bou27 = Button(fen1, text='27', width =4, command=lambda :num(27))
    bou27.grid(row =0,column =27)
    bou28 = Button(fen1, text='28', width =4, command=lambda :num(28))
    bou28.grid(row =0,column =28)
    bou29 = Button(fen1, text='29', width =4, command=lambda :num(29))
    bou29.grid(row =0,column =29)
     
    bou30 = Button(fen1, text='30', width =4, command=lambda :num(30))
    bou30.grid(row =0,column =30)
    bou31 = Button(fen1, text='31', width =4, command=lambda :num(31))
    bou31.grid(row =0,column =31)
    bou32 = Button(fen1, text='32', width =4, command=lambda :num(32))
    bou32.grid(row =0,column =32)
    bou33 = Button(fen1, text='33', width =4, command=lambda :num(33))
    bou33.grid(row =0,column =33)
    bou34 = Button(fen1, text='34', width =4, command=lambda :num(34))
    bou34.grid(row =0,column =34)
    bou35 = Button(fen1, text='35', width =4, command=lambda :num(35))
    bou35.grid(row =0,column =35)
    bou36 = Button(fen1, text='36', width =4, command=lambda :num(36))
    bou36.grid(row =0,column =36)
     
    bour = Button(fen1, text='reto', width =4,command=reto )
    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

  5. #5
    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
    Par défaut
    C'est normal, à chaque fois que tu cliques sur un bouton, tu recrée autant de Label. Un moment le programme sature.
    Il te faut simplement changer la valeur des des Labels.
    Et au lieu de créer 36 boutons, factorise le code en utilisant une liste:
    J'ai juste corrigé la fonction num
    =>

    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
    # -*- coding: cp1252 -*-
    from Tkinter import *
    # définition des gestionnaires
    # d'événements :
     
    def reto() :
        global cpt,nbf,nob,nobcont
       # print 'reto nobcont',nobcont
       # print 'reto nob',nob
        cpt[nob]=nobcont
        #nbf[no]=nbf[no]+1
        txt1 = Label(fen1, text = cpt[nob])
       # txt2 = Label(fen1, text = nbf[no])
        txt1.grid(row =1,column=nob)
        #txt2.grid(row =2,column=no)
        t = range(37)
        for a in t:
            if a <> nob:
                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)
     
    def num(no) :
        global cpt,nbf,nob,nobcont
        print 'num cpt',cpt, no
        nob=no
        # print 'num nob',nob
        nobcont =cpt[no]
        # print 'num nobcont',nobcont
        cpt[no]=0
     
        #nbf[no]=nbf[no]+1
        txt[no].config(text = cpt[no])
        #txt2.grid(row =2,column=no)
        t = range(37)
        for a in t:
            if a != no:
                cpt[a]=cpt[a]+1
                txt[a].config(text = cpt[a])
     
     
    #========== Programme principal =============
     
    # les variables suivantes seront utilisées de manière globale :
    no,npb =0,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("compteur")
    print 'cpt',cpt
    bouq = Button(fen1,text='Quit', width =4,command=fen1.quit)
    bouq.grid(row =4,column =3)
     
     
    txt = []
    for i in range(37):
        txt.append(Label(fen1, text=cpt[i]))
        txt[i].grid(row = 1, column = i)
     
    bou = []
    for i in range(37):
        bou.append(Button(fen1, text=str(i), width =4, command =lambda x=i:num(x)))
        bou[i].grid(row = 0, column = i)
     
     
     
    bour = Button(fen1, text='reto', width =4,command=reto )
    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
    Je te laisse corriger la fonction reto

  6. #6
    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 ça y est ça marche super!!
    Merci encore une fois, au de python
    j'ai juste une question, je ne comprends pas comment marche l'expression suivante : txt[nob].config(text = cpt[nob])

  7. #7
    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
    Par défaut
    - txt[no] correspond au Label sur lequel tu as cliqué vu que txt a été définie comme une liste et no est le noième label dans cette liste
    - la fonction config() permet de récupérer tous les attributs d'un widget Tkinter.
    - et si tu rajoutes des paramètres dans config, tu peux les modifier

  8. #8
    Membre confirmé
    Inscrit en
    Octobre 2007
    Messages
    32
    Détails du profil
    Informations forums :
    Inscription : Octobre 2007
    Messages : 32
    Par défaut
    je parlais bien de compilation, et c'est dans la faq

    http://python.developpez.com/faq/?page=Py2exe

  9. #9
    Membre expérimenté
    Profil pro
    Étudiant
    Inscrit en
    Avril 2007
    Messages
    181
    Détails du profil
    Informations personnelles :
    Âge : 37
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2007
    Messages : 181
    Par défaut
    Les options de tous les widgets Tkinter sont représentées sous la forme d'un dictionnaire, mon_widget.config() retourne le dictionnaire complet.
    Si on appelle la méthode config avec un argument (ou plusieurs), cela permet de régler la valeur d'une des options du dictionnaire (c'est en fait l'usage le plus courant de config).

    Si on veut juste récupérer la valeur d'une option, il faut utiliser cget :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    mon_widget.cget("clef")
    où clef est une chaîne représentant une des clef du dictionnaire des options. Tkinter conserve tout

    @mon_pierre : ce n'est pas vraiment de la compilation non plus.
    C'est plutôt de l'empaquetage, en fournissant les bibliothèques python sous forme de DLL pour les plateformes microsoft qui n'ont pas l'interpréteur Python installé...
    Non seulement ça ne doit pas améliorer le temps d'exécution, mais en plus c'est absolument inutile pour les systèmes GNU/Linux, Mac OS, *BSD, etc.

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

Discussions similaires

  1. Réponses: 1
    Dernier message: 19/06/2014, 14h47
  2. Réponses: 9
    Dernier message: 25/05/2012, 08h40
  3. [LV 8.2] Nombre de clics limités en face avant ?
    Par Red_Cap dans le forum LabVIEW
    Réponses: 3
    Dernier message: 06/07/2010, 15h22
  4. Limiter le nombre de clic sur bouton en javascript
    Par hoangeric dans le forum Général JavaScript
    Réponses: 5
    Dernier message: 31/07/2009, 13h33
  5. Limiter le nombre de clic sur un bouton
    Par Sulthisil dans le forum wxWidgets
    Réponses: 2
    Dernier message: 27/05/2007, 23h33

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