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 :

Problème fermeture de l'interface sans avoir fermé la figure


Sujet :

Tkinter Python

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre habitué
    Homme Profil pro
    Étudiant
    Inscrit en
    Juillet 2017
    Messages
    13
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Gard (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juillet 2017
    Messages : 13
    Par défaut Problème fermeture de l'interface sans avoir fermé la figure
    Bonjour à tous,
    Je débute sur Python et suis confronté à un problème... bien qu'ayant cherché et lu de nombreuses discussions, je ne trouve pas l'origine.

    Mon programme ouvre dans une interface différents choix à sélectionner (choisir 1 parmi les deux paramètres)
    Une fois avoir choisi mes deux paramètres, je clique sur entrer et une fenêtre s'ouvre ; merveilleux ma figure se dessine dans mon repère. Mais le soucis c'est que je ne peux pas cliquer sur mon interface avant d'avoir fermer le dessin !! D'où mon problème ; j'aimerai pouvoir choisir plusieurs paramètres dans mon interface et que plusieurs courbes se dessinent sur ma figure.

    (Comment puis-je copier le code ici correctement avec les indentations ?)

    Merci de votre précieuse aide,

    Bien à vous

  2. #2
    Membre confirmé
    Homme Profil pro
    Étudiant
    Inscrit en
    Juillet 2016
    Messages
    132
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 27
    Localisation : France, Indre et Loire (Centre)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Industrie

    Informations forums :
    Inscription : Juillet 2016
    Messages : 132
    Par défaut
    Bonjour,

    Quels modules utilises tu ?
    Pour ton interface et tes tracés ?

    Valentin

  3. #3
    Membre habitué
    Homme Profil pro
    Étudiant
    Inscrit en
    Juillet 2017
    Messages
    13
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Gard (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juillet 2017
    Messages : 13
    Par défaut
    Bonjour,

    j'utilise tkinter et matplotlib

    Adrian

  4. #4
    Membre confirmé
    Homme Profil pro
    Étudiant
    Inscrit en
    Juillet 2016
    Messages
    132
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 27
    Localisation : France, Indre et Loire (Centre)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Industrie

    Informations forums :
    Inscription : Juillet 2016
    Messages : 132
    Par défaut
    Bonjour,

    as tu un code ?
    Pour que l'on puisse comprendre d'où vient l'erreur.

    Parce que personnellement je ne vois pas tellement d'où ça pourrait venir, ça marche très bien et facilement chez moi :

    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
    import matplotlib.pyplot as plt
    import numpy as np
    import tkinter as tk
     
    def fonction(argument):
        ydata=[]
        xdata=[i for i in np.arange(0,10,0.01)]
        if argument ==1:
            for i in xdata:
               ydata.append(f(i))
        elif argument==0:
           ydata=xdata
        addPlot(xdata,ydata)
     
    def f(x):
        return x**2
     
     
    def addPlot(xdata,ydata):
        graph = plt.subplot()
        graph.plot(xdata, ydata)
        plt.show()
     
    root = tk.Tk()
    Boutonf=tk.Button(root, text='f(x)', command=lambda :fonction(1))
    Boutonx=tk.Button(root, text='x', command= lambda :fonction(0))
    Boutonf.grid(row=1)
    Boutonx.grid(row=0)
    root.mainloop()

    EDIT : oups j'avais mal relu ton message pour copier ton code il suffit d'utiliser les bornes CODE qui se trouvent dans les options d'écriture de ton message (bouton # à droite).
    Sinon tapes : (CODE) ici ton code (/CODE) en remplaçant les parathèse en crochets [ ]

    Valentin

  5. #5
    Membre habitué
    Homme Profil pro
    Étudiant
    Inscrit en
    Juillet 2017
    Messages
    13
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Gard (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juillet 2017
    Messages : 13
    Par défaut
    C'est surement dans la syntaxe de formulation de mon code que j'ai du me planter quelque part ...
    Voici le code :
    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
    from tkinter import *
    from numpy import tan, pi
    import matplotlib.pyplot as plt
    import numpy as np
    from math import tan, pi
     
     
    def directions(choix, choix1):
        #définir pour chaque cas une coordonnée centrale ÃÂ* chaque repère dans le plan
        #premier bateau ÃÂ* 0.0 , et choix comme origine du deuxième bateau ÃÂ* 10.15 par exemple
        #pour ce faire il faut créer un message box dans l'interface
     
       coord = {'x': 0, 'y': 0}
       x = list(range(-80, 80, 10))
       L = 10
     
     
       if choix =='N' and choix1 =='E':
           print(x)
           #x=[i for i in x if i > 0]
           y=[i*tan(pi/6) for i in x]
           y=[-i for i in y]
           print(x, y)
           y2=[i-L for i in y]
     
     
       elif choix =='S' and choix1 =='E':
           print(x)
           #x=[i for i in x if i > 0]
           y=[i*tan(pi/6) for i in x]
           y=[i for i in y]
           print(x, y)
           y2=[i+L for i in y]
    ##        x=+x
    ##       y=x*tan(30)
    ##       y=+y
    ##       y2=y-L
     
     
       elif choix =='N' and choix1 =='W':
            x=[-i for i in x]
            print(x)
            y=[i*tan(pi/6) for i in x]
            #y=[i for i in y]
            print(x, y)
            y2=[i-L for i in y]
     
     
    ##       x=-x
    ##       y=x*tan(30)
    ##       y=+y
    ##       y2=y-L
     
       elif choix =='S' and choix1 =='W':
            print(x)
           #x=[i for i in x if i > 0]
            y=[i*tan(pi/6) for i in x]
            y=[-i for i in y]
            print(x, y)
            y2=[i+L for i in y]
     
    ##       x=-x
    ##       y=x*tan(30)
    ##       y=-y
    ##       y2=y+L
     
       elif choix =='E' and choix1 =='N':
            print(x)
           #x=[i for i in x if i > 0]
            y=[i*tan(pi/3) for i in x]
            y=[-i for i in y]
            print(x, y)
            y2=[i-2*L for i in y]
     
    ##       x=-x
    ##       y=x*tan(60)
    ##       y=-y
    ##       y2=y-2*L
     
       elif choix =='E' and choix1 =='S':
            print(x)
           #x=[i for i in x if i > 0]
            y=[i*tan(pi/3) for i in x]
            y=[+i for i in y]
            print(x, y)
            y2=[i+2*L for i in y]
     
    ##       x=+x
    ##       y=x*tan(60)
    ##       y=+y
    ##       y2=y+2*L
     
       elif choix =='W' and choix1 =='N':
            print(x)
           #x=[i for i in x if i > 0]
            y=[i*tan(pi/3) for i in x]
            y=[+i for i in y]
            print(x, y)
            y2=[i-2*L for i in y]
     
    ##       x=+x
    ##       y=x*tan(60)
    ##       y=+y
    ##       y2=y-2*L
     
       elif choix =='W' and choix1 =='S':
            print(x)
           #x=[i for i in x if i > 0]
            y=[i*tan(pi/3) for i in x]
            y=[-i for i in y]
            print(x, y)
            y2=[i-2*L for i in y]
     
     
    ##       x=+x
    ##       y=x*tan(60)
    ##       y=-y
    ##       y2=y+2*L
     
    #FIN SCRIPT 8 _ DEBUT SCRIPT 16
     
       elif choix =='NE' and choix1 =='SE':
           print(x)
           #x=[i for i in x if i > 0]
           y=[i*tan(pi/2.4) for i in x]
           y=[-i for i in y]
           print(x, y)
           y2=[i-2*L for i in y]
     
     
       elif choix =='SE' and choix1 =='SW':
           print(x)
           #x=[i for i in x if i > 0]
           y=[i*tan(pi/12) for i in x]
           y=[+i for i in y]
           print(x, y)
           y2=[i+2*L for i in y]
     
     
       elif choix =='SW' and choix1 =='NW':
           print(x)
           #x=[i for i in x if i > 0]
           y=[i*tan(pi/2.4) for i in x]
           y=[-i for i in y]
           print(x, y)
           y2=[i+2*L for i in y]
     
     
       elif choix =='NW' and choix1 =='NE':
           print(x)
           #x=[i for i in x if i > 0]
           y=[i*tan(pi/12) for i in x]
           y=[i for i in y]
           print(x, y)
           y2=[i-2*L for i in y]
     
     
       elif choix =='SE' and choix1 =='NE':
           print(x)
           #x=[i for i in x if i > 0]
           y=[i*tan(pi/2.4) for i in x]
           y=[i for i in y]
           print(x, y)
           y2=[i+2*L for i in y]
     
       elif choix =='NE' and choix1 =='NW':
           print(x)
           #x=[i for i in x if i > 0]
           y=[i*tan(pi/12) for i in x]
           y=[-i for i in y]
           print(x, y)
           y2=[i-2*L for i in y]
     
       elif choix =='NW' and choix1 =='SW':
           print(x)
           #x=[i for i in x if i > 0]
           y=[i*tan(pi/2.4) for i in x]
           y=[i for i in y]
           print(x, y)
           y2=[i-2*L for i in y]
     
     
       elif choix =='SW' and choix1 =='SE':
           print(x)
           #x=[i for i in x if i > 0]
           y=[i*tan(pi/12) for i in x]
           y=[-i for i in y]
           print(x, y)
           y2=[i+2*L for i in y]
     
     
        # TRACE
     
       x = [i + coord['x'] for i in x]
       y = [i + coord['y'] for i in y]
       y2 = [i + coord['y'] for i in y2]
     
     
       plt.axhline(0, color='black')
       plt.axvline(0, color='black')
       plt.plot(x,y)
       plt.plot(x,y2)
       plt.fill_between(x, y, y2, color='pink', edgecolor='black', hatch="/")
       plt.ylabel('S to N')
       plt.xlabel('W to E')
       plt.xlim(-80, 80)
       plt.ylim(-80, 80)
       plt.show()
       return y,y2
     
     
     
     
     
     
    choix=None
    choix1=None
     
     
    # fonctions qui servent pour la mise en page
    def texte(fenetre,texte):
        a=Label(fenetre,text=str(texte))
        a.pack()
     
    def button_action():
        global choix, choix1
        wind_direction=choix.get()
        boat_direction=choix1.get()
        directions(wind_direction, boat_direction)
     
    def bouton_entrer(fenetre,texte):
        bouton_quit=Button(fenetre,text=texte,command=button_action)
        bouton_quit.pack()
     
     
    def boat():
        global choix, choix1
     
        fenetre=Tk()
        fenetre.quit()
     
       # SELECT WIND DIRECTION AND BOAT DIRECTION.
        choix=StringVar()
        texte(fenetre,"WIND DIRECTION")
        E=Radiobutton(fenetre,text="EAST",variable=choix,value="E")
        W=Radiobutton(fenetre,text="WEST",variable=choix,value="W")
        N=Radiobutton(fenetre,text="NORTH",variable=choix,value="N")
        S=Radiobutton(fenetre,text="SOUTH",variable=choix,value="S")
        NE=Radiobutton(fenetre,text="NORTH EAST",variable=choix,value="NE")
        SE=Radiobutton(fenetre,text="SOUTH EAST",variable=choix,value="SE")
        SW=Radiobutton(fenetre,text="SOUTH WEST" ,variable=choix,value="SW")
        NW=Radiobutton(fenetre,text="NORTH WEST" ,variable=choix,value="NW")
        E.pack()
        W.pack()
        N.pack()
        S.pack()
        NE.pack()
        SE.pack()
        SW.pack()
        NW.pack()
        texte(fenetre,"BOAT DIRECTION")
        choix1=StringVar()
        E=Radiobutton(fenetre,text="EAST",variable=choix1,value="E")
        W=Radiobutton(fenetre,text="WEST",variable=choix1,value="W")
        N=Radiobutton(fenetre,text="NORTH",variable=choix1,value="N")
        S=Radiobutton(fenetre,text="SOUTH",variable=choix1,value="S")
        SE=Radiobutton(fenetre,text="SOUTH EAST",variable=choix1,value="SE")
        SW=Radiobutton(fenetre,text="SOUTH WEST",variable=choix1,value="SW")
        NW=Radiobutton(fenetre,text="NORTH WEST",variable=choix1,value="NW")
        NE=Radiobutton(fenetre,text="NORTH EAST",variable=choix1,value="NE")
        E.pack()
        W.pack()
        N.pack()
        S.pack()
        SE.pack()
        SW.pack()
        NW.pack()
        NE.pack()
        #Bouton Entrer
        bouton_entrer(fenetre,"Entrer")
        #Mainloop
        fenetre.mainloop()

  6. #6
    Membre confirmé
    Homme Profil pro
    Étudiant
    Inscrit en
    Juillet 2016
    Messages
    132
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 27
    Localisation : France, Indre et Loire (Centre)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Industrie

    Informations forums :
    Inscription : Juillet 2016
    Messages : 132
    Par défaut
    Je n'ai pas reussis à lancer ton programme, mais j'ai vu que tu utilisais un plot mets plutot des subplot.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
       plt.axhline(0, color='black')
       plt.axvline(0, color='black')
       plt.plot(x,y)
       plt.plot(x,y2)
       plt.fill_between(x, y, y2, color='pink', edgecolor='black', hatch="/")
       plt.ylabel('S to N')
       plt.xlabel('W to E')
       plt.xlim(-80, 80)
       plt.ylim(-80, 80)
       plt.show()
       return y,y2
    Valentin

Discussions similaires

  1. Réponses: 0
    Dernier message: 10/05/2017, 11h18
  2. Réponses: 8
    Dernier message: 12/12/2014, 22h03
  3. Lancer interface GUI sans avoir Matlab.
    Par Lachauche dans le forum Interfaces Graphiques
    Réponses: 1
    Dernier message: 07/05/2014, 20h00
  4. Réponses: 2
    Dernier message: 20/07/2012, 10h24
  5. [Free Pascal] [Vista] La fenêtre se ferme sans avoir le temps de voir le résultat
    Par cheylard dans le forum Free Pascal
    Réponses: 2
    Dernier message: 09/01/2009, 22h20

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