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 :

erreur idle sur python 3.9 et sur python 3.4 [Python 3.X]


Sujet :

Python

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Homme Profil pro
    Gestionnaire de parc micro-informatique
    Inscrit en
    Juillet 2015
    Messages
    19
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Gestionnaire de parc micro-informatique
    Secteur : Service public

    Informations forums :
    Inscription : Juillet 2015
    Messages : 19
    Par défaut erreur idle sur python 3.9 et sur python 3.4
    bonjour


    Sur python 3.4 pas d'erreur, mais sur python 3.9 j'ai une erreur
    Voici l'erreur
    Merci pour vos réponses
    Cordialement

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    Python 3.9.1 (tags/v3.9.1:1e5d33e, Dec  7 2020, 17:08:21) [MSC v.1927 64 bit (AMD64)] on win32
    Type "help", "copyright", "credits" or "license()" for more information.
    >>> 
    =================== RESTART: C:\Users\rico\Desktop\essais.py ===================
    Exception in Tkinter callback
    Traceback (most recent call last):
      File "C:\Users\rico\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 1884, in __call__
        return self.func(*args)
      File "C:\Users\rico\Desktop\essais.py", line 165, in clic_choix
        self.E4.insert(0,self.lisbox_choix.get(index))
      File "C:\Users\rico\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 3183, in get
        return self.tk.call(self._w, 'get', first)
    _tkinter.TclError: bad listbox index "": must be active, anchor, end, @x,y, or a number


    Code python : 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
     
    from tkinter import ttk
    from tkinter import *
     
    fenetre=Tk()
    fenetre.title("BANQUE")
    fenetre.geometry("1250x700+10+10")
     
    #fenetre.update_idletask()
    width = fenetre.winfo_width()
    height = fenetre.winfo_height()
     
    width = 1250
    height = 700
     
    x = (fenetre.winfo_screenwidth()//2)-(width//2)
    y = (fenetre.winfo_screenheight()//2)-(height//2)
    fenetre.geometry('{}x{}+{}+{}'.format(width,height,x,y))
     
     
                    ###################################
                    ##########                 ########
                    ##########     DEBUT       ########
                    ##########    TABLEAU      ########                 
                    ##########      TOUS       ########
                    ##########                 ######## 
                    ###################################
     
    class   Tableau_Tous:
        def __init__(self):
     
            """Constructeur de la fenêtre principale"""
     
                        #####################
     
                # ENTETE TABLEAU 
            self.Frame1= Frame(fenetre)
            self.Frame1.grid(row=0, column=0,padx=5,pady=5 )
     
                #####################
     
                # ENTETE TABLEAU 
            self.Frame2= Frame(fenetre)
            self.Frame2.grid(row=1, column=0,padx=0,pady=0 )
     
                #####################
     
                # LABEL RECUP CHOIX
            self.Frame3= Frame(fenetre)
            self.Frame3.grid(row=2, column=0,padx=5,pady=5 )
     
                #####################
     
                # LISBOX
            self.Frame4= Frame(fenetre)
            self.Frame4.grid(row=3, column=0,padx=5,pady=5 )
     
                #######################
                 # BOUTON
            self.Frame7 = Frame(fenetre)
            self.Frame7.grid(row=6, column=0,padx=0,pady=5 )
     
                ########################
     
            label=Label(self.Frame1,text = "TABLEAU" ,fg='red',bg='yellow',
                            font=("arial",15,"bold italic"))
            label.grid(row=0,column=0,columnspan=8)                    
     
                # Bouton  "Terminer"      
            bt_terminer = Button(self.Frame7,text='Terminer',bg='green3',
                    font=("arial",12,"bold italic"),fg='black',
                    command = Vider_Frame)
            bt_terminer.grid(row=0,column=3,padx=50)
     
                # appel la fonction <remplissage_liste>
            self.remplissage_liste()
     
                ######## ENTETE DU TABLEAU ######################          
     
            L4 = Label(self.Frame2, text="Choix\n",
                    relief=RIDGE,width=11,fg='yellow',bg='red',
                    font=("arial",12,"bold italic"))
            L4.grid(row=0,column=3,padx=3)        
     
            L7 = Label(self.Frame2,text="Bénéficiaire\n",
                    relief=RIDGE,width=17,fg='yellow',bg='red',
                    font=("arial",12,"bold italic"))
            L7.grid(row=0,column=6,padx=3)
     
     
                    # Fin entête du tableau
     
        ################################################################                               
     
            self.E4 = Entry(self.Frame3, 
                    relief=RIDGE,width=13,fg='red',bg='yellow',
                    justify='center',font=("arial",12,"bold italic"))
            self.E4.grid(row=0,column=3,padx=5)
            self.E4.insert(0,"Tous")         
     
            self.E7 = Entry(self.Frame3,#Bénéficiaire
                    relief=RIDGE,width=21,fg='red',bg='yellow',
                    justify='center',font=("arial",12,"bold italic"))
            self.E7.grid(row=0,column=6,padx=5)
            self.E7.insert(0,"Tous")         
     
                #################
     
            self.toutes_les_listbox()#appel fonction
     
     
     
        def toutes_les_listbox(self):       
     
                ################# lISTBOX CHOIX ##########################
     
                self.barre = Scrollbar(self.Frame4, orient=VERTICAL)
                self.lisbox_choix = Listbox(self.Frame4,bg='chartreuse',fg='blue',
                    height=5,width=11,font=("arial",12,"bold italic"))
                self.barre.config(command = self.lisbox_choix.yview)
                self.lisbox_choix.config(yscrollcommand = self.barre.set, )
                self.lisbox_choix.grid(column=6, row=0,padx=5)
                self.barre.grid(column=7, row=0, sticky=S+N)
     
                for x in self.liste_choix:
                    self.lisbox_choix.insert(END,x)
     
                self.lisbox_choix.bind("<<ListboxSelect>>", self.clic_choix)
     
     
     
                ################# lISTBOX BENEFICIAIRE ##########################
     
                self.barre = Scrollbar(self.Frame4, orient=VERTICAL)
                self.lisbox_select = Listbox(self.Frame4,bg='chartreuse',fg='blue',
                    height=5,width=19,font=("arial",12,"bold italic"))
                self.barre.config(command = self.lisbox_select.yview)
                self.lisbox_select.config(yscrollcommand = self.barre.set, )
                self.lisbox_select.grid(column=12, row=0,padx=5) 
                self.barre.grid(column=13, row=0, sticky=S+N)
     
                for x in self.liste_select:
                    self.lisbox_select.insert(END,x)
     
                self.lisbox_select.bind("<<ListboxSelect>>", self.clic_select)
     
     
        def remplissage_liste(self):       
     
            self.liste_choix = []
            self.liste_select = []
     
     
            self.liste_choix = ['Carte','Cheque','Virement','Prelevement']
            self.liste_choix.insert(0,'Tous')
     
            self.liste_select = ['carrefour','lidl','geant','superU']
            self.liste_select.insert(0,'Tous')
     
     
        def clic_choix(self,evt):        
            # Récupère le choix
            index = self.lisbox_choix.curselection()
            self.E4.config(state=NORMAL)# permet l'écriture
            self.E4.delete(0,END) # vide l'entry
            self.E4.insert(0,self.lisbox_choix.get(index))
            # Inscrit le choix dans l'Entry       
     
        def clic_select(self,evt):        
            # Récupère le choix
            index = self.lisbox_select.curselection()
            self.E7.config(state=NORMAL)# permet l'écriture
            self.E7.delete(0,END) # vide l'entry
            self.E7.insert(0,self.lisbox_select.get(index))
            # Inscrit le choix dans l'Entry
     
     
                     ###################################
                    ##########                 ########
                    ##########       FIN       ########
                    ##########     TABLEAU     ########                 
                    ##########       TOUS      ########                 
                    ##########                 ######## 
                    ###################################
     
                #################################
                ########                 ########
                ########  DEBUT CLASS    ########
                ########     VIDER       ########
                ########     FRAME       ########
                ########                 ########
                #################################       
     
    class Vider_Frame :
        def __init__(self):
     
            for widget in fenetre.winfo_children():
                widget.grid_forget()
     
                    #################################
                    ########                 ########
                    ########   FIN CLASS     ########
                    ########     VIDER       ########
                    ########     FRAME       ########
                    ########                 ########
                    #################################
     
    menubar = Menu(fenetre)
     
    ######################## TABLEAU ####################
     
    menu4 = Menu(menubar, tearoff=0)
    menu4.add_command(label="Tous", command = Tableau_Tous)# 2195
     
    menu4.add_separator()
    menu4.add_command(label="Quitter", command=fenetre.quit)
     
    menubar.add_cascade(label="Tableau", menu=menu4)
     
    fenetre.config(menu=menubar)
     
    fenetre.mainloop()

  2. #2
    Expert confirmé

    Homme Profil pro
    Inscrit en
    Octobre 2008
    Messages
    4 307
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2008
    Messages : 4 307
    Par défaut
    Salut,

    Ajoute un print pour voir ce que donne "index":
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
        def clic_choix(self,evt):        
            # Récupère le choix
            index = self.lisbox_choix.curselection()
            print("index:", index)
    Voir là: http://tkinter.fdex.eu/doc/lbw.html#...x.curselection

  3. #3
    Expert éminent
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 742
    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 742
    Par défaut
    Salut,

    Le problème est qu'avec plusieurs Listbox, par défaut, un bind sur <<ListboxSelect>> va appeler le callback lorsque la Selection (globale) change.

    Du coup, si on clique sur un item de la première Listbox, le callback de la 2ème sera aussi appelé et ce qui est retourné par .curselection() sera la chaine vide (d'où l'erreur).

    Créez vos Listbox avec exportselection=0.

    Et pensez à tester vos dialogues avec les widgets sur de petits exemples: dommage de se rendre compte après avoir écrit 200 lignes de code que çà ne fait pas ce qu'on veut.

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

  4. #4
    Membre averti
    Homme Profil pro
    Gestionnaire de parc micro-informatique
    Inscrit en
    Juillet 2015
    Messages
    19
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Gestionnaire de parc micro-informatique
    Secteur : Service public

    Informations forums :
    Inscription : Juillet 2015
    Messages : 19
    Par défaut Merci pour les réponses
    Bonjour

    Je vous remercie pour les réponses :

    Avec < exportselection=False> le problème est résolu

    J'avais écrit ce petit programme de 2595 lignes avec python 3.4 (aucun problème) et j'ai voulu l'améliorer avec python 3.9

    mais le problème est apparu.

    Je vous ai mis seulement une synthèse de ce programme pour vous montrer le problème car il y a 10 lisbox .

    Merci encore pour la solution et pour votre rapidité

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

Discussions similaires

  1. Erreur 145 sur table mysql
    Par ramses83 dans le forum Requêtes
    Réponses: 1
    Dernier message: 06/09/2007, 21h09
  2. [VB.NET] Erreur OnMouseUp sur Datagrid
    Par daner06 dans le forum Windows Forms
    Réponses: 2
    Dernier message: 19/01/2005, 10h26
  3. [Kylix] erreur time.sur kylix avec redhat 9.0
    Par sumco dans le forum EDI
    Réponses: 4
    Dernier message: 20/05/2004, 15h13
  4. Réponses: 9
    Dernier message: 27/04/2004, 11h01
  5. [VB6] Erreur 9 sur redim preserve
    Par tomnie dans le forum VB 6 et antérieur
    Réponses: 2
    Dernier message: 22/10/2002, 17h29

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