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

Python Discussion :

Actualiser une interface avec timer


Sujet :

Python

  1. #1
    Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2016
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2016
    Messages : 2
    Points : 3
    Points
    3
    Par défaut Actualiser une interface avec timer
    Bonjour,

    j'ai un petit souci pour actualiser un calcul sur mon interface, le programme étant un générateur de calcul mental avec différents niveaux je cherche à actualiser les résultats après que l'utilisateur est entré une réponse bizarrement j'arrive à actualiser pour le niveau facile mais pas pour les autres.
    Merci pour votre aide.

    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
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
    617
    618
    619
    620
    621
    622
    623
    624
    625
    626
    627
    628
    629
    630
    631
    632
    633
    634
    635
    636
    637
    638
    639
    640
    641
    642
    643
    644
    645
    646
    647
    648
    649
    650
    651
    652
    653
    654
    655
    656
    657
    658
    659
    660
    661
    662
    663
    664
    665
    666
    667
    668
    669
    670
    671
    672
    673
    674
    675
    676
    677
    678
    679
    680
    681
    682
    683
    684
    685
    686
    687
    688
    689
    690
    691
    692
    693
    694
    695
    696
    697
    698
    699
    700
    701
    702
    703
    704
    705
    706
    707
    708
    709
    710
    711
    712
    713
    714
    715
    716
    717
    718
    719
    720
    721
    722
    723
    724
    725
    726
    727
    728
    729
    730
    731
    732
    733
    734
    735
    736
    737
    738
    739
    740
    741
    742
    743
    744
    745
    746
    747
    748
    749
    750
    751
    752
    753
    754
    755
     
    from Tkinter import *
    import tkFont
    import Tix
    from math import *
    from random import *
    import random
    import sys
    from threading import Thread
    import time
    #======================Variables======================
    global i
    global Calcul1
    global showinfo
    global Result
    global resu1
    global Moins
    global La
    global Lb
    global Egal
    global Plus
    global Fois
    global o
    global n
    global q
    accueil=0
    o=False
    n=False
    q=False
    i=50
     
    #=====================Fonctions pour lancer les pages==================
     
    def fonction1():
        pagecalculFACILE()
     
    def fonction2():
        pagecalculMOYEN()
     
    def fonction3():
        pagecalculDIFFICILE()    
     
    #======================Fonctions de verifications=======================#
    def verif1():
        global o
        global n
        global q
        global resu1
        global Moins
        global La
        global Lb
        global Egal
        global Plus
        global a
        global goF
        global goM
        global goD
        global s
     
        resu2=int(Result.get())
     
     
        if resu2==resu1:
     
            Moins.destroy()
            La.destroy()
            Lb.destroy()
            Egal.destroy()
            Result.update()
     
            print 'bravo'
            goF()
            o=True
            n=True
            q=True
     
        elif resu2!=resu1:
            Moins.destroy()
            La.destroy()
            Lb.destroy()
            Egal.destroy()
            Result.update()
     
            print 'dommage'
            goF()
            o=True
            n=True
            q=True
     
    def verif2():
        global o
        global resu1
        global Moins
        global La
        global Lb
        global Egal
        global Plus
        global goF
        global goM
        global goD
     
        resu2=int(Result.get())
     
     
        if resu2==resu1:
     
            Plus.destroy()
            La.destroy()
            Lb.destroy()
            Egal.destroy()
            Result.update()
     
            print 'bravo'
            goF()
            o=True
            n=True
            q=True
     
        elif resu2!=resu1:
            Plus.destroy()
            La.destroy()
            Lb.destroy()
            Egal.destroy()
            Result.update()
     
            print 'dommage'
            goF()
            o=True
            n=True
            q=True
     
    def verif3():
        global resu1
        global Fois
        global La
        global Lb
        global Egal
        global Plus
        global goM
        global goD
        global goF
     
        resu2=int(Result.get())
     
     
        if resu2==resu1:
     
            Fois.destroy()
            La.destroy()
            Lb.destroy()
            Egal.destroy()
            Result.update()
     
            print 'bravo'
            n=True
            q=True
     
        elif resu2!=resu1:
            Fois.destroy()
            La.destroy()
            Lb.destroy()
            Egal.destroy()
            Result.update()
     
            print 'dommage'
            n=True
            q=True
     
     
    if o==True:
        pagecalculFACILE.update()
    if n==True:
        goM()
        pagecalculMOYEN.update()
    if q==True:
        goD()
        pagecalculDIFFICILE.update()
     
     
     
    #==========================Première interface, l'accueil dès l'ouverture du programme===============#
     
    def paccueil():         
     
        global i
        accueil=Tk()
        accueil.update()    
        accueil.title('Générateur de calcul mental');
        accueil.geometry("800x480");
     
        police=tkFont.Font(accueil, size=25, family='Courier');
        police.config(size=25, family='Courier');
     
        ImageFond=PhotoImage(file='Tableau.gif')  
        FondAccueil=Canvas(accueil, width=800, height=480)
        FondAccueil.create_image(0,0,image=ImageFond, anchor=NW)
        FondAccueil.create_text(410,55,text="CALCUL MENTAL",font=('Courier',50,'bold','underline'));
        FondAccueil.place(x=0,y=0)
        police=tkFont.Font(accueil, size=25, family='Courier');
        police.config(size=25, family='Courier');                                                           #Definition des boutons des niveaux de difficultés#
     
        FondBF=PhotoImage(file='BFacile.gif')                                                               #Bouton Facile#
        BFacile=Button(accueil,image=FondBF,text="Facile",relief=GROOVE,command=fonction1);
        BFacile.place(x=225,y=125);
     
        FondBM=PhotoImage(file='BMoyen.gif')                                                                #Bouton Moyen#
        BMoyen=Button(accueil,image=FondBM,relief=GROOVE,command=fonction2);
        BMoyen.place(x=225,y=225);
     
        FondBD=PhotoImage(file='BDifficile.gif')                                                            #Bouton Difficile#
        BDifficile=Button(accueil,image=FondBD,relief=GROOVE,command=fonction3);
        BDifficile.place(x=225,y=325);
     
     
        PhotoHS=PhotoImage(file='HighScore1.gif');                                                          #Definition du bouton high score#
        Bhs=Button(accueil, image=PhotoHS, relief=GROOVE,command=pageHS);
        Bhs.place(x=720,y=400);
     
     
     
        accueil.mainloop();
     
     
    #==================Deuxième interface : la page principale avec les calculs FACILES==========================#
     
    def pagecalculFACILE():                                       
     
        pagecalculFACILE=Toplevel(accueil);
     
        global i
        global Result
        global resu1
        global goF
     
     
        def goF():
     
     
            global resu1        
            global i
            global Moins
            global La
            global Lb
            global Egal
            global Plus
     
     
            Bgo.destroy()
     
            #======Génération des variables======#
            a = random.randint(0,30)
     
            b = random.randint(0,30)
     
            Signe=random.randint(1,2)
     
     
            while i!=0:             #======Timer======#
     
     
                h=0  
     
                i=(i-1)
     
                time.sleep (1)
     
                Timer.update()
     
                Timer.config(text=i)
     
                #========Création des calculs signe MOINS=======#
                if h==0:
     
                    if Signe==1:
     
                        resu1=a-b
     
                        Moins=Label(pagecalculFACILE,text="-",height=2,width=2,font='courier 20')
                        Moins.place(x=325,y=120)
                        La=Label(pagecalculFACILE,text=a,height=2,width=2,font='courier 20')
                        La.place(x=275,y=120)
                        Lb=Label(pagecalculFACILE,text=b,height=2,width=2,font='courier 20')
                        Lb.place(x=375,y=120)
                        Egal=Label(pagecalculFACILE,text="=",height=2,width=2,font='courier 20')
                        Egal.place(x=425,y=120)
                        Result.get()
     
                        #=====Bouton vérification=====#
                        Verif=Button(pagecalculFACILE,text="Vérifier",relief=GROOVE,command=verif1,height=3,width=5)
                        Verif.place(x=325,y=200)
     
                        if i==0:
                            h=1
                            Timer.config(text="Fini !")
                            La.destroy()
                            Lb.destroy()
                            Egal.destroy()
                            Moins.destroy()
                            nomjoueur()
     
     
                #========Création des calculs signe PLUS=======#                
     
                    if Signe==2:
     
     
                        resu1=a+b
     
                        Plus=Label(pagecalculFACILE,text="+",height=2,width=2,font='courier 20')
                        Plus.place(x=325,y=120)
                        La=Label(pagecalculFACILE,text=a,height=2,width=2,font='courier 20')
                        La.place(x=275,y=120)
                        Lb=Label(pagecalculFACILE,text=b,height=2,width=2,font='courier 20')
                        Lb.place(x=375,y=120)
                        Egal=Label(pagecalculFACILE,text="=",height=2,width=2,font='courier 20')
                        Egal.place(x=425,y=120)
                        Result.get()
     
                        Verif=Button(pagecalculFACILE,text="Vérifier",relief=GROOVE,command=verif2,height=3,width=5)
                        Verif.place(x=325,y=200)
     
                        if i==0:
                            h=1
                            Timer.config(text="Fini !")
                            La.destroy()
                            Lb.destroy()
                            Egal.destroy()
                            Plus.destroy()
                            nomjoueur()
     
     
     
     
        pagecalculFACILE.title('Générateur de calcul mental');
        pagecalculFACILE.geometry("800x480");
     
     
     
    #=========Aspect de l'interface=========#    
     
        ImageFond=PhotoImage(file='Tableau.gif')
     
        FondPP=Canvas(pagecalculFACILE, width=800, height=480, bg="blue");
        FondPP.create_image(0,0,image=ImageFond, anchor=NW)
        FondPP.create_text(410,50,text="Mode Facile",font=('Courier',50,'bold','underline'));
        FondPP.place(x=0,y=0);
     
        QRestantes=Label(pagecalculFACILE,text="/15",height=3,width=15)
        QRestantes.place(x=700,y=430);
        Result=Entry(pagecalculFACILE,textvariable=" ",width=10)
        Result.config(font='courier 35')
        Result.getint()
        Result.place(x=265,y=250)
     
                                                                                           #Saisie du résultat
        Timer=Label(pagecalculFACILE,text="Prêt ?",height=2,width=20)                  #Label du timer#
        Timer.place(x=50,y=30)
     
        Bgo=Button(pagecalculFACILE, relief=GROOVE,text="Go !",command=goF,height=3,width=20)
        Bgo.place(x=50,y=70)    
     
        pagecalculFACILE.mainloop();
     
     
    #=========================Deuxième interface : la page principale avec les calculs MOYENS=============================#
     
    def pagecalculMOYEN():                                                                 
     
     
        pagecalculMOYEN=Toplevel(accueil);
        global i
        global Result
        global resu1
     
        def goM():
     
     
            global resu1        
            global i
            global Moins
            global La
            global Lb
            global Egal
            global Plus
            global Fois
     
            i=10
     
            Bgo.destroy()
     
            #======Génération des variables======#
     
            a = random.randint(0,30)
     
            b = random.randint(0,30)
     
            Signe=random.randint(1,2)
     
     
     
            while i!=0:             #======Timer======#
     
     
                h=0  
     
                i=(i-1)
     
                time.sleep (1)
     
                Timer.update()
     
                Timer.config(text=i)
     
                #========Création des calculs signe MOINS=======#
     
                if h==0:
     
                    if Signe==1:
     
                        resu1=a-b
     
                        Moins=Label(pagecalculMOYEN,text="-",height=2,width=2,font='courier 20')
                        Moins.place(x=300,y=120)
                        La=Label(pagecalculMOYEN,text=a,height=2,width=2,font='courier 20')
                        La.place(x=250,y=120)
                        Lb=Label(pagecalculMOYEN,text=b,height=2,width=2,font='courier 20')
                        Lb.place(x=350,y=120)
                        Egal=Label(pagecalculMOYEN,text="=",height=2,width=2,font='courier 20')
                        Egal.place(x=400,y=120)
                        Result.get()
     
                        #=====Bouton vérification=====#
     
                        Verif=Button(pagecalculMOYEN,text="Vérifier",relief=GROOVE,command=verif1,height=3,width=5)
                        Verif.place(x=325,y=200)
     
                        if i==0:
                            h=1
                            Timer.config(text="Fini !")
                            La.destroy()
                            Lb.destroy()
                            Egal.destroy()
                            Moins.destroy()
                            nomjoueur()
     
     
                #========Création des calculs signe PLUS=======#                
     
                    if Signe==2:
     
     
                        resu1=a+b
     
                        Plus=Label(pagecalculMOYEN,text="+",height=2,width=2,font='courier 20')
                        Plus.place(x=300,y=120)
                        La=Label(pagecalculMOYEN,text=a,height=2,width=2,font='courier 20')
                        La.place(x=250,y=120)
                        Lb=Label(pagecalculMOYEN,text=b,height=2,width=2,font='courier 20')
                        Lb.place(x=350,y=120)
                        Egal=Label(pagecalculMOYEN,text="=",height=2,width=2,font='courier 20')
                        Egal.place(x=400,y=120)
                        Result.get()
     
                        Verif=Button(pagecalculMOYEN,text="Vérifier",relief=GROOVE,command=verif2,height=3,width=5)
                        Verif.place(x=325,y=200)
     
                        if i==0:
                            h=1
                            Timer.config(text="Fini !")
                            La.destroy()
                            Lb.destroy()
                            Egal.destroy()
                            Plus.destroy()
                            nomjoueur()
     
     
                #========Création des calculs signe FOIS=======#
     
                    if Signe==3:
     
                        resu1=a*b
     
                        Fois=Label(pagecalculMOYEN,text="x",height=2,width=2,font='courier 20')
                        Fois.place(x=300,y=120)
                        La=Label(pagecalculMOYEN,text=a,height=2,width=2,font='courier 20')
                        La.place(x=250,y=120)
                        Lb=Label(pagecalculMOYEN,text=b,height=2,width=2,font='courier 20')
                        Lb.place(x=350,y=120)
                        Egal=Label(pagecalculMOYEN,text="=",height=2,width=2,font='courier 20')
                        Egal.place(x=400,y=120)
                        Result.get()
     
                        Verif=Button(pagecalculMOYEN,text="Vérifier",relief=GROOVE,command=verif3,height=3,width=5)
                        Verif.place(x=325,y=200)
     
                        if i==0:
                            h=1
                            Timer.config(text="Fini !")
                            La.destroy()
                            Lb.destroy()
                            Egal.destroy()
                            Fois.destroy()
                            nomjoueur()
     
     
     
    #=========Aspect de l'interface=========#
     
        pagecalculMOYEN.title('Générateur de calcul mental');
        pagecalculMOYEN.geometry("800x480");
     
        ImageFond=PhotoImage(file='Tableau.gif')    
        FondPP2=Canvas(pagecalculMOYEN, width=800, height=480, bg="blue");
        FondPP2.create_image(0,0,image=ImageFond, anchor=NW)
        FondPP2.create_text(410,50,text="Mode Moyen",font=('Courier',50,'bold','underline'));
        FondPP2.place(x=0,y=0);
     
        Timer=Label(pagecalculMOYEN,text="Timer",height=5,width=15)                            #Label du timer#
        Timer.place(x=0,y=0);
     
        QRestantes2=Label(pagecalculMOYEN,text="/15",height=3,width=15)
        QRestantes2.place(x=700,y=430);
     
     
        Result=Entry(pagecalculMOYEN,width=10)                                                 #Saisie du résultat#
        Result.config(font='courier 35')
        Result.place(x=265,y=250)
        Bgo=Button(pagecalculMOYEN, relief=GROOVE,command=goM,height=3,width=20)
        Bgo.place(x=50,y=70)    
     
     
        pagecalculMOYEN.mainloop();
     
     
     
    #####################################################################################################################################
    #####################################################################################################################################
    #####################################################################################################################################
     
     
    def pagecalculDIFFICILE():                                                                 #Deuxième interface : la page principale avec les calculs FACILES#
     
        global i
        global Result
        global resu1
        pagecalculDIFFICILE=Toplevel(accueil);
     
     
        def goD():
     
     
            global resu1        
            global i
            global Moins
            global La
            global Lb
            global Egal
            global Plus
            global Fois
     
            i=10
     
            Bgo.destroy()
     
            #======Génération des variables======#
     
            a= random.randint(0,100)
     
            b= random.randint(0,100)
     
            Signe=random.randint(1,3)
     
            a = (float(a))/10
     
            b = (float (b))/10
     
     
     
            while i!=0:             #======Timer======#
     
     
                h=0  
     
                i=(i-1)
     
                time.sleep (1)
     
                Timer.update()
     
                Timer.config(text=i)
     
                #========Création des calculs signe MOINS=======#
     
                if h==0:
     
                    if Signe==1:
     
                        resu1=a-b
     
                        Moins=Label(pagecalculDIFFICILE,text="-",height=2,width=2,font='courier 20')
                        Moins.place(x=300,y=120)
                        La=Label(pagecalculDIFFICILE,text=a,height=2,width=2,font='courier 20')
                        La.place(x=250,y=120)
                        Lb=Label(pagecalculDIFFICILE,text=b,height=2,width=2,font='courier 20')
                        Lb.place(x=350,y=120)
                        Egal=Label(pagecalculDIFFICILE,text="=",height=2,width=2,font='courier 20')
                        Egal.place(x=400,y=120)
                        Result.get()
     
                        #=====Bouton vérification=====#
     
                        Verif=Button(pagecalculDIFFICILE,text="Vérifier",relief=GROOVE,command=verif1,height=3,width=5)
                        Verif.place(x=325,y=200)
     
                        if i==0:
                            h=1
                            Timer.config(text="Fini !")
                            La.destroy()
                            Lb.destroy()
                            Egal.destroy()
                            Moins.destroy()
                            nomjoueur()
     
     
                #========Création des calculs signe PLUS=======#                
     
                    if Signe==2:
     
     
                        resu1=a+b
     
                        Plus=Label(pagecalculDIFFICILE,text="+",height=2,width=2,font='courier 20')
                        Plus.place(x=300,y=120)
                        La=Label(pagecalculDIFFICILE,text=a,height=2,width=2,font='courier 20')
                        La.place(x=250,y=120)
                        Lb=Label(pagecalculDIFFICILE,text=b,height=2,width=2,font='courier 20')
                        Lb.place(x=350,y=120)
                        Egal=Label(pagecalculDIFFICILE,text="=",height=2,width=2,font='courier 20')
                        Egal.place(x=400,y=120)
                        Result.get()
     
                        Verif=Button(pagecalculDIFFICILE,text="Vérifier",relief=GROOVE,command=verif2,height=3,width=5)
                        Verif.place(x=325,y=200)
     
                        if i==0:
                            h=1
                            Timer.config(text="Fini !")
                            La.destroy()
                            Lb.destroy()
                            Egal.destroy()
                            Plus.destroy()
                            nomjoueur()
     
     
                #========Création des calculs signe FOIS=======#
     
                    if Signe==3:
     
                        resu1=a*b
     
                        Fois=Label(pagecalculDIFFICILE,text="x",height=2,width=2,font='courier 20')
                        Fois.place(x=300,y=120)
                        La=Label(pagecalculDIFFICILE,text=a,height=2,width=2,font='courier 20')
                        La.place(x=250,y=120)
                        Lb=Label(pagecalculDIFFICILE,text=b,height=2,width=2,font='courier 20')
                        Lb.place(x=350,y=120)
                        Egal=Label(pagecalculDIFFICILE,text="=",height=2,width=2,font='courier 20')
                        Egal.place(x=400,y=120)
                        Result.get()
     
                        Verif=Button(pagecalculDIFFICILE,text="Vérifier",relief=GROOVE,command=verif3,height=3,width=5)
                        Verif.place(x=325,y=200)
     
                        if i==0:
                            h=1
                            Timer.config(text="Fini !")
                            La.destroy()
                            Lb.destroy()
                            Egal.destroy()
                            Fois.destroy()
                            nomjoueur()
     
     
     
     
        pagecalculDIFFICILE.title('Générateur de calcul mental');
        pagecalculDIFFICILE.geometry("800x480");
     
     
        ImageFond=PhotoImage(file='Tableau.gif')    
        FondPP3=Canvas(pagecalculDIFFICILE, width=800, height=480, bg="blue");
        FondPP3.create_image(0,0,image=ImageFond, anchor=NW)
        FondPP3.create_text(410,50,text="Mode Difficile",font=('Courier',50,'bold','underline'));
        FondPP3.place(x=0,y=0);
     
        Timer=Label(pagecalculDIFFICILE,text="Timer",height=5,width=15)                            #Label du timer#
        Timer.place(x=0,y=0);
     
        QRestantes3=Label(pagecalculDIFFICILE,text="/15",height=3,width=15)
        QRestantes3.place(x=700,y=430);
     
     
     
        Result=Entry(pagecalculDIFFICILE,width=10)                                                 #Saisie du résultat#
        Result.config(font='courier 35')
        Result.place(x=265,y=250)
        Bgo=Button(pagecalculDIFFICILE, relief=GROOVE,command=goD,height=3,width=20)
        Bgo.place(x=50,y=70)    
     
     
     
        pagecalculDIFFICILE.mainloop();
     
    #####################################################################################################################################
    #####################################################################################################################################
    #####################################################################################################################################
     
    def nomjoueur():                                                                        #Fenetre pour rentrer son nom#
        global i
        nom=Toplevel(accueil)
        nom.title('Nom du joueur')
        nom.geometry('200x100')
        OK=Button(nom,text="OK",width=20)
        Lnom=Label(nom,text="Entrer votre nom :")
        Enom=Entry(nom)
        OK.place(x=30,y=60)
        Lnom.place(x=35,y=0)
        Enom.place(x=30,y=30)
        nom.mainloop()
     
    #####################################################################################################################################
    #####################################################################################################################################
    #####################################################################################################################################
     
     
    def pageHS():
        global i
        pageHS=Tk();
        pageHS.title('Générateur de calcul mental');
        pageHS.geometry("800x480");
     
        ImageFond=PhotoImage(file='Tableau.gif')
        FondHS=Canvas(pageHS, width=800, height=480);
        FondHS.create_image(0,0,image=ImageFond, anchor=NW)
        FondHS.create_text(410,50,text="High-Score",font=('Courier',45,'bold','underline'))
        FondHS.place(x=0,y=0);
        pageHS.mainloop()
     
     
    #####################################################################################################################################
    #####################################################################################################################################
     
     
     
    paccueil()
    Images attachées Images attachées       

  2. #2
    Membre confirmé
    Homme Profil pro
    Développeur banc de test
    Inscrit en
    Mai 2014
    Messages
    199
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Développeur banc de test
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Mai 2014
    Messages : 199
    Points : 482
    Points
    482
    Par défaut
    Bonjour,

    premier soucis repéré c'est l'utilisation d'une même variable pour décrire une fonction et instancier l'interface Toplevel:

    def pagecalculFACILE():
    pagecalculFACILE=Toplevel(accueil);

    def pagecalculMOYEN():
    pagecalculMOYEN=Toplevel(accueil);

    def pagecalculDIFFICILE():
    pagecalculDIFFICILE=Toplevel(accueil);

    ça posera problème si on revient sur le menu principal, les fonctions n'existeront plus.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    if o==True:
        pagecalculFACILE.update()
    if n==True:
        goM()
        pagecalculMOYEN.update()
    if q==True:
        goD()
        pagecalculDIFFICILE.update()
    Le code suivant ne fait pas parti d'une fonction ? Il n'y a pas d'indentation et donc va être exécuté au lancement du script, sauf que pagecalculFACILE, pagecalculMOYEN et pagecalculDIFFICILE n'existent pas encore.


    Avant d'aller plus loin dans l'investigation vous devriez sérieusement songer à simplifier votre code, le fait d'avoir dupliqué pagecalcul pour les trois niveaux vous amène 3 fois plus de problèmes.

    Soit en utilisant une fonction générique dont vous faites passer l'instance tkinter, soit en utilisant une classe.

    Parce que ce quand vous allez modifier ou corriger dans un niveau de difficulté il faudra faire de même dans les 2 autres fonctions, c'est une perte de temps énorme et vous allez forcément oublier quelque chose en route.
    Le plus gros mal d'un codage c'est le copier-collé, on oublie toujours un truc.

    Et si on appelle plus d'une fois un même code c'est qu'on peut en écrire une fonction.

  3. #3
    Expert éminent sénior
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 241
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Manche (Basse Normandie)

    Informations professionnelles :
    Activité : Architecte technique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2008
    Messages : 21 241
    Points : 36 698
    Points
    36 698
    Par défaut
    Salut,

    L'usage de time.sleep() et d'appels à .update() avec tkinter est dangereux.
    L'implication est que pas grand monde ira chercher pourquoi votre code ne fonctionne pas et vous recommandera d'utiliser une autre méthode.

    Je comprends que "penser" avec tkinter i.e. des callbacks sans programmer objet devient prise de tête lorsque le code devient un peu touffu. Sans POO et en essayant de rester proche de la structure de votre code, je vous propose d'étudier la mécanique du code suivant:
    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
    import Tkinter as tk
     
    def start_play(delay, count):
     
        def do_handle_answer():
            nonlocal count
            count -= 1
            answer_button.configure(text='click left %d' % count)
            if count == 0:
                root.quit()    
     
        timeout = False
        timer_id = None
     
        def start_timer(delay_ms=1000):
            nonlocal timeout, timer_id, delay
     
            timer_label.configure(text=delay)
            delay -= 1
            if delay >= 0: 
                timer_id = root.after(delay_ms, start_timer)
            else:
                timeout = True
                root.quit()
        # mise à jour de l'affichage        
        menu_window.pack_forget()
        timer_label.configure(text=delay) 
        answer_button.configure(text='click left %d' % count, command=do_handle_answer)      
        player_window.pack(fill='both')
        # logique de saisie avec timer
        start_timer()
        while 1:
            root.mainloop()
            if count == 0:
                root.after_cancel(timer_id)
                break
            if timeout:
                break
        # on regarde pourquoi on est sorti de la boucle
        print ('count', count, 'timeout', timeout)
        # remise en place du menu.
        player_window.pack_forget()
        menu_window.pack(fill='both')
     
     
    root = tk.Tk()
    root.geometry('500x500')
    # menu.
    menu_window = tk.Frame(root)
    for x in range(3):
        name = 'page_%d' % x
        tk.Button(menu_window, text=name, command=lambda x=x: start_play(5*(x+1), 3)).pack()
    menu_window.pack(fill='both')
     
    player_window = tk.Frame(root)
    timer_label = tk.Label(player_window)
    timer_label.pack()
     
    answer_button = tk.Button(player_window)
    answer_button.pack()
     
    tk.mainloop()
    Ca se contente de lancer un affichage ou l'utilisateur dois cliquer 3 fois avant que le timer expire.
    A la sortie on affiche le résultat via "print" et on re-affiche le menu.
    Pas besoin de créer et détruire à chaque fois: on affiche et on met à jour des objets accessibles via des variables globales.
    Bon courage,

    - W
    Architectures post-modernes.
    Python sur DVP c'est aussi des FAQs, des cours et tutoriels

Discussions similaires

  1. [POO] réaliser une 'interface' avec PHP4
    Par TabrisLeFol dans le forum Langage
    Réponses: 3
    Dernier message: 27/12/2008, 22h00
  2. Exécuter une interface avec Matlab 5.3
    Par chaterbache dans le forum Interfaces Graphiques
    Réponses: 4
    Dernier message: 02/01/2008, 08h08
  3. Réponses: 36
    Dernier message: 23/05/2007, 18h54
  4. creer une page avec timer pour 2 URLS
    Par anubisme dans le forum Langage
    Réponses: 4
    Dernier message: 21/04/2006, 12h03
  5. Piloter une interface avec des relais
    Par Yepazix dans le forum API, COM et SDKs
    Réponses: 13
    Dernier message: 26/10/2004, 20h46

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