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 :

liste non reconnu dans liste déroulante


Sujet :

Python

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Août 2017
    Messages
    141
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 55
    Localisation : France, Seine et Marne (Île de France)

    Informations professionnelles :
    Activité : Technicien maintenance

    Informations forums :
    Inscription : Août 2017
    Messages : 141
    Par défaut liste non reconnu dans liste déroulante
    Bonjour,

    Je passe par Tkinter et des Radiobutton qui selon le choix doivent mettre à jour ma liste déroulante : "objListDeroul" via la variable "lstLogging01" qui contient ma liste modifiée selon le choix du RadioButton.

    Une partie du 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
    #   ____________________________________________________________________________________________________________________
    #   ____________________________________________________________________________________________________________________
    # Les fonctions
    def foncBout():
     
     
     
        print(varChoixList.get())
     
     
        #pass    #bout01 = Radiobutton(objFrame3, text=varChoix01, variable=varChoixList, value=1, bg=varCoulPrinc, command=foncBout)
     
     
     
        lstLogging =[]                                          #   Création liste pour la liste déroulante
        for indice, e in enumerate(carnet_code.lstCarnet):
     
            if e.numlist == varChoixList.get():         #   On ne prend que la liste qui nous interesse (1 à 6) lors de l'ouverture du prg
                lstLogging.append(e.log)
        #   Création new list pour qu'elle soit triée
        lstLogging01 = list(lstLogging)
        lstLogging01.sort()
     
     
     
     
     
     
        #   Création de la liste des logging pour la liste déroulante
        objListDeroul = ttk.Combobox(objFrame3, values=lstLogging01, width=16)       #   Récup des valeurs : logging et trie
        objListDeroul.bind('<<ComboboxSelected>>', foncBtLstDeroul)
     
        print(lstLogging)
        print(lstLogging01)
     
        # prend en compte le choix du bouton mais ne met pas a jour la liste déroulante, pourquoi ?

    lstLogging01 me donne bien les bonnes valeurs mais la liste ne se met pas à jour.

    Le code en entier :
    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
    import os.path
    import pickle
    import tkinter as tk              #   Pour menu
    import tkinter.ttk as ttk
    from tkinter import *
    """ *****************************
        DOCSTRING
        Gestionnaire de mots de passe
        *****************************
        """
     
    #   ____________________________________________________________________________________________________________________
    #   ____________________________________________________________________________________________________________________
    # Création de l'instance Tk
    fen1 =Tk()
     
    #   ____________________________________________________________________________________________________________________
    #   ____________________________________________________________________________________________________________________
    # Les constantes
    NOMDOS = os.getcwd()                    #   Nom du dossier courant
    NOMFIC = "Codes_LesClasses_01"          #   Nom du fichier
    PHOTO1 = PhotoImage(file='Icone30x30_add.png')
    PHOTO2 = PhotoImage(file='Icone30x30_modif.png')
    PHOTO3 = PhotoImage(file='Icone30x30_sup.png')
    PHOTO4 = PhotoImage(file='Icone30x30_Exit.png')
    PHOTO5 = PhotoImage(file='Icone30x30_valid.png')
    PHOTO6 = PhotoImage(file='Icone30x30_info.png')
    PHOTO7 = PhotoImage(file='Icone30x30_precedent.png')
    PHOTO8 = PhotoImage(file='Icone30x30_suivant.png')
    PHOTO_HELP01 = PhotoImage(file="Help_01.png")
     
    #   ____________________________________________________________________________________________________________________
    #   ____________________________________________________________________________________________________________________
    # Les classes
    class ClassCarnet(object):
        def __init__(self):
            self.lstCarnet = []
     
        def ajouter_fiche(self, fiche_new):
            self.lstCarnet.append(fiche_new)
     
        def sauver(self):
            with open(NOMFIC, "wb") as fichier:
                pickle.dump(self, fichier)
     
    class FicheCode(object):
        def __init__(self, log=None, code=None, renseig=None, truque=0, numlist=None):
            #   initialise les 3 attributs
            self.log = log
            self.code = code
            self.renseig = renseig
            self.truque = truque
            self.numlist = numlist
     
    #   ____________________________________________________________________________________________________________________
    #   ____________________________________________________________________________________________________________________
    # Les fonctions
    def foncBout():
     
     
     
        print(varChoixList.get())  # pour test
     
        lstLogging =[]                                          #   Création liste pour la liste déroulante
        for indice, e in enumerate(carnet_code.lstCarnet):
     
            if e.numlist == varChoixList.get():         #   On ne prend que la liste qui nous interesse (1 à 6) lors de l'ouverture du prg
                lstLogging.append(e.log)
        #   Création new list pour qu'elle soit triée
        lstLogging01 = list(lstLogging)
        lstLogging01.sort()
     
     
     
     
     
     
        #   Création de la liste des logging pour la liste déroulante
        objListDeroul = ttk.Combobox(objFrame3, values=lstLogging01, width=16)       #   Récup des valeurs : logging et trie
        objListDeroul.bind('<<ComboboxSelected>>', foncBtLstDeroul)
     
        print(lstLogging)
        print(lstLogging01)
     
        #prend en compte le choix du bouton mais ne met pas a jour la liste déroulante, pourquoi ?
     
     
     
     
     
    def foncBout02():
        pass
     
    def foncBout03():
        pass
     
    def foncBout04():
        pass
     
    def foncBout05():
        pass
     
    def foncBout06():
        pass
     
     
     
     
     
     
     
    def foncBtLstDeroul(object):
        """ Récupère la valeur choisi de la liste déroulante : (Logging)
        et renvoi dans les champs, les données"""
        #   Récup du N° de la liste dans cette liste principale (index (1er champ))
        a = lstLogging.index(objListDeroul.get())        #   lstLogging donne ce qu'il y a d'inscrit dans la liste déroulante et non pas la liste réelle
        #   Inscription
        objLogging.configure(text=carnet_code.lstCarnet[a].log)
        objCode.configure(text=carnet_code.lstCarnet[a].code)
        objRenseig.configure(text=carnet_code.lstCarnet[a].renseig)
        if carnet_code.lstCarnet[a].truque == 0:
            objTruquee.deselect()
        else:
            objTruquee.select()
        #   Dégrisé les boutons MODIF et SUP
        bouModif.configure(state = "active")
        bouSup.configure(state = "active")
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    def foncBoutNew():
        print(lstLogging01)
     
    def foncBoutModif():
        pass
     
    def foncBoutSup():
        pass
     
    def fonc6ChoixReinit01():
        pass
     
    def fonc6ChoixReinit02():
        pass
     
    def fonc6ChoixReinit03():
        pass
     
    def fonc6ChoixReinit04():
        pass
     
    def fonc6ChoixReinit05():
        pass
     
    def fonc6ChoixReinit06():
        pass
     
    def fonc6ChoixReinitTous():
        pass
     
    def fonc6ChoixModif01():
        pass
     
    def fonc6ChoixModif02():
        pass
     
    def fonc6ChoixModif03():
        pass
     
    def fonc6ChoixModif04():
        pass
     
    def fonc6ChoixModif05():
        pass
     
    def fonc6ChoixModif06():
        pass
     
    def foncHelpPage01():
        pass
     
     
     
     
     
    #   ____________________________________________________________________________________________________________________
    #   ____________________________________________________________________________________________________________________
    #  MAIN : Lancement du programme Principal
    if  os.path.exists(NOMFIC):                                 #   Récupération du fichier NOMFIC (Liste des log)
        with open(NOMFIC, "rb") as fichier:
            carnet_code =  pickle.load(fichier)
    else:
        carnet_code = ClassCarnet()
    #   ____________________________________________________________________________________________________________________
    #   Variables locales
    varCoulPrinc = "Sea Green"
    varCoulSecon = "Medium Sea Green"
    #   ____________________________________________________________________________________________________________________
    #   Création fenêtre principale
    fen1.geometry('480x400+590+325')
    fen1.title("Codes")
    fen1.configure(bg = varCoulPrinc)
    #   ____________________________________________________________________________________________________________________
    #   Créations - Les frames
    objFrame1 = LabelFrame(fen1, text="Résultat", padx=20, pady=5, bg=varCoulPrinc)
    objFrame2 = LabelFrame(fen1, text="Recherche et création", padx=20, pady=5, bg=varCoulPrinc)
    #   Créa frames dans frame : objFrame2
    objFrame3 = LabelFrame(objFrame2, text="Recherche", padx=20, pady=5, bg=varCoulPrinc)
    #   ____________________________________________________________________________________________________________________
    #   Créations - Les objets
    #   Créa objet logging
    objLabel1 = Label(objFrame1 ,height=1 ,width=20, text="Logging", bg=varCoulPrinc)
    objLogging = Label(objFrame1 ,height=1 ,width=20, bg="Medium Sea Green", relief=SUNKEN)
    #   Créa objet code
    objLabel2 = Label(objFrame1 ,height=1 ,width=20, text="Code", bg=varCoulPrinc)
    objCode = Label(objFrame1 ,height=1 ,width=20, bg=varCoulSecon, relief=SUNKEN)
    #   Créa objet bouton truquée
    varTruqueeO_N =0  # initialisation de la variable cochée ou pas
    objTruquee = Checkbutton(objFrame1, variable=varTruqueeO_N, bg=varCoulPrinc, text="Truquée ?", activebackground=varCoulPrinc)  # varTruqueeO_N : 0= décochée, 1=cochée
    #   Créa objet renseignements
    objLabel3 = Label(objFrame1 ,height=1 ,width=47, text="Renseignements", bg=varCoulPrinc)
    objRenseig = Label(objFrame1 ,height=5 ,width=47, bg=varCoulSecon, relief=SUNKEN)
    #   ____________________________________________________________________________________________________________________
    #   Créations - Boutons poussoir
    varChoixList = IntVar()                          #   varChoixList est une variable qui contiendra la valeur du bouton que l'on coche
    #   Récup de ces variables
    Fichier = open("0_Codes_variables.txt", "r")
    varChaine = Fichier.read()
    Fichier.close()
    #   Modification de ces variables en fonction du fichier : "0_Codes_variables.txt"
    #   varPosition donne la position des "|" pour séparer les 6 choix
    varPosition =  varChaine.find("|")
    varPosition2 = varChaine.find("|",varPosition+1)
    varPosition3 = varChaine.find("|",varPosition2+1)
    varPosition4 = varChaine.find("|",varPosition3+1)
    varPosition5 = varChaine.find("|",varPosition4+1)
    varPosition6 = len(varChaine)
    varNomList = varChaine[:varPosition]    #   pour le msgBox de création de nouvelle fiche afin que cela indique le nom de la liste 1
    #   Modification des variables en séparant le texte du fichier via la variable varChaine
    varChoix01 = varChaine[:varPosition]
    varChoix02 = varChaine[varPosition+1:varPosition2]
    varChoix03 = varChaine[varPosition2+1:varPosition3]
    varChoix04 = varChaine[varPosition3+1:varPosition4]
    varChoix05 = varChaine[varPosition4+1:varPosition5]
    varChoix06 = varChaine[varPosition5+1:varPosition6]
    #   Création des Radiobutton
    bout01 = Radiobutton(objFrame3, text=varChoix01, variable=varChoixList, value=1, bg=varCoulPrinc, command=foncBout)
    bout02 = Radiobutton(objFrame3, text=varChoix02, variable=varChoixList, value=2, bg=varCoulPrinc, command=foncBout)
    bout03 = Radiobutton(objFrame3, text=varChoix03, variable=varChoixList, value=3, bg=varCoulPrinc, command=foncBout)
    bout04 = Radiobutton(objFrame3, text=varChoix04, variable=varChoixList, value=4, bg=varCoulPrinc, command=foncBout)
    bout05 = Radiobutton(objFrame3, text=varChoix05, variable=varChoixList, value=5, bg=varCoulPrinc, command=foncBout)
    bout06 = Radiobutton(objFrame3, text=varChoix06, variable=varChoixList, value=6, bg=varCoulPrinc, command=foncBout)
    # Radiobutton qui doit être coché de base
    bout01.select()
    #   ____________________________________________________________________________________________________________________
    #   Créations - liste déroulante
    lstLogging =[]                                          #   Création liste pour la liste déroulante
    for indice, e in enumerate(carnet_code.lstCarnet):
     
        if e.numlist == 1:         #   On ne prend que la liste qui nous interesse (1 à 6) lors de l'ouverture du prg
            lstLogging.append(e.log)
    #   Création new list pour qu'elle soit triée
    lstLogging01 = list(lstLogging)
    lstLogging01.sort()
    #   Création de la liste des logging pour la liste déroulante
    objListDeroul = ttk.Combobox(objFrame3, values=lstLogging01, width=16)       #   Récup des valeurs : logging et trie
    objListDeroul.bind('<<ComboboxSelected>>', foncBtLstDeroul)
     
     
     
    #   ____________________________________________________________________________________________________________________
    #   Créations - Boutons hors-frames
    bouNew =Button(fen1, image=PHOTO1, bg="Sea Green", command=foncBoutNew)
    bouModif =Button(fen1, image=PHOTO2, bg="Sea Green", command=foncBoutModif, state="disabled", activebackground="Sea Green")  # disabled, "active" = pointeur sur bouton, "normal" = ben normal
    bouSup =Button(fen1, image=PHOTO3, bg="Sea Green", command=foncBoutSup, state="disabled", activebackground="Sea Green")
    bouQuit =Button(fen1, image=PHOTO4, bg="Sea Green", command=fen1.destroy)
    #   ____________________________________________________________________________________________________________________
    #   Créations - Barre de menus
    objMenubar = tk.Menu(fen1)
    #   Menus principaux
    menuReinit = tk.Menu(objMenubar, tearoff=0)
    menuModif = tk.Menu(objMenubar, tearoff=0)
    menuHelp = tk.Menu(objMenubar, tearoff=0)
    #   Menus principaux titres
    objMenubar.add_cascade(label='Réinitialisation', menu=menuReinit)
    objMenubar.add_cascade(label='Modification', menu=menuModif)
    objMenubar.add_cascade(label='Help', menu=menuHelp)
    #   Menus
    menuReinit.add_command(label="Reinitialisation choix 01", command=fonc6ChoixReinit01)
    menuReinit.add_command(label="Reinitialisation choix 02", command=fonc6ChoixReinit02)
    menuReinit.add_command(label="Reinitialisation choix 03", command=fonc6ChoixReinit03)
    menuReinit.add_command(label="Reinitialisation choix 04", command=fonc6ChoixReinit04)
    menuReinit.add_command(label="Reinitialisation choix 05", command=fonc6ChoixReinit05)
    menuReinit.add_command(label="Reinitialisation choix 06", command=fonc6ChoixReinit06)
    menuReinit.add_command(label="Reinitialisation Tous", command=fonc6ChoixReinitTous)
    menuModif.add_command(label="Modification choix 01", command=fonc6ChoixModif01)
    menuModif.add_command(label="Modification choix 02", command=fonc6ChoixModif02)
    menuModif.add_command(label="Modification choix 03", command=fonc6ChoixModif03)
    menuModif.add_command(label="Modification choix 04", command=fonc6ChoixModif04)
    menuModif.add_command(label="Modification choix 05", command=fonc6ChoixModif05)
    menuModif.add_command(label="Modification choix 06", command=fonc6ChoixModif06)
    menuHelp.add_command(label='Help !', command=foncHelpPage01)
    #   Affichage de la barre de menu
    fen1.config(menu=objMenubar)
    #   ____________________________________________________________________________________________________________________
    #   Positionnements objets
    #   positionnement des frames
    objFrame1.pack(fill="both", expand="yes", padx=5, pady=5)   # fill both : extension a yes donc both sinon que sur x ou y
    objFrame2.pack(fill="both", expand="yes", padx=5, pady=5)
    objFrame3.pack(fill="both", expand="yes")
    #   Position des labels et zones de texte
    objLabel1.grid(row=0, sticky=W, padx=5, pady=(5 ,0))
    objLabel2.grid(row=0 ,column=1, padx=(40 ,5), pady=(5 ,0))
    objLabel3.grid(row=2 ,column=0, padx=5, columnspan=2, sticky=W, pady=(15 ,0))
    objLogging.grid(row=1, sticky=W, padx=5, pady=(0 ,5))
    objCode.grid(row=1 ,column=1, padx=(40 ,5), pady=(0 ,5))
    objTruquee.grid(row=1 ,column=2, padx=(0 ,5), pady=(0 ,5))
    objRenseig.grid(row=3 ,column=0, padx=5, columnspan=2, sticky=W, pady=(0 ,5))
    #   Position des Radiobutton
    bout01.grid(row=0 ,column=0, sticky=W)
    bout02.grid(row=0 ,column=1, sticky=W)
    bout03.grid(row=0 ,column=2, sticky=W)
    bout04.grid(row=1 ,column=0, sticky=W)
    bout05.grid(row=1 ,column=1, sticky=W)
    bout06.grid(row=1 ,column=2, sticky=W)
    #   Position des Liste déroulante
    objListDeroul.grid(row=0 ,column=3, sticky=E, padx=(30 ,0))
    #   Position des boutons externes
    bouNew.pack(side=LEFT)
    bouModif.pack(side=LEFT)
    bouSup.pack(side=LEFT)
    bouQuit.pack(side=RIGHT)
    #   ____________________________________________________________________________________________________________________
    #   Réception d'événements
    fen1.mainloop()

  2. #2
    Expert éminent
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 739
    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 739
    Par défaut
    Citation Envoyé par Ragus1970 Voir le message
    Je passe par Tkinter et des Radiobutton qui selon le choix doivent mettre à jour ma liste déroulante : "objListDeroul" via la variable "lstLogging01" qui contient ma liste modifiée selon le choix du RadioButton.
    Vous ne mettez pas à jour objListDeroul mais vous créez une autre ttk.Combobox (qui n'est même pas affichée).
    Les mises à jour se font via la méthode .configure(....).

    Et si vous vous donniez la peine de reproduire ce cas d'utilisation en quelques lignes de code plutôt que de poster 250 lignes de code qui n'apportent rien au problème, j'aurais pu partir de là pour vous montrer comment çà se modifie...

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

  3. #3
    Membre confirmé
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Août 2017
    Messages
    141
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 55
    Localisation : France, Seine et Marne (Île de France)

    Informations professionnelles :
    Activité : Technicien maintenance

    Informations forums :
    Inscription : Août 2017
    Messages : 141
    Par défaut
    Bonjour,

    Bon vous me mettez le nez dans le caca, OK.
    Pour ne pas avoir a lire 250 lignes, j'ai mis un morceau de code, le tout c'est au cas ou cela ne suffirais pas. La prochaine fois je ferais mieux !

    En tout cas merci, j'ai compris le problème, je devrais me débrouiller.

  4. #4
    Membre confirmé
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Août 2017
    Messages
    141
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 55
    Localisation : France, Seine et Marne (Île de France)

    Informations professionnelles :
    Activité : Technicien maintenance

    Informations forums :
    Inscription : Août 2017
    Messages : 141
    Par défaut
    Bonjour,

    Merci ça marche, j'ai juste remplacé :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    objListDeroul = ttk.Combobox(objFrame3, values=lstLogging01, width=16)
    par


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    objListDeroul.configure(values=lstLogging01)

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

Discussions similaires

  1. Variable dans Main non reconduite dans list
    Par nico_1 dans le forum MkFramework
    Réponses: 2
    Dernier message: 03/02/2014, 11h20
  2. [Flex4] Valeur non incluse dans listes déroulantes
    Par granchef dans le forum Flex
    Réponses: 3
    Dernier message: 06/07/2013, 17h08
  3. [Batch] Copier Fichiers A vers B si NON present dans liste.txt
    Par scotop dans le forum Scripts/Batch
    Réponses: 15
    Dernier message: 05/04/2013, 01h51
  4. Dropdown liste non reconnue par la table
    Par demouzz dans le forum Modélisation
    Réponses: 3
    Dernier message: 22/09/2008, 16h50
  5. Utilisation de structure non constante dans <list>
    Par bleuerouge dans le forum SL & STL
    Réponses: 4
    Dernier message: 17/07/2008, 10h01

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