2011-05-20 6 views
2

Je travaille actuellement sur un éditeur d'image en Python avec Tkinter (je sais que Python n'est pas le meilleur pour l'édition d'image mais c'est pour l'école, je n'ai pas choisi) et ce que j'essaie faire est d'enregistrer tous les fichiers ouverts dans un autre fichier pour ajouter un raccourci vers les cinq derniers dans le menu Fichier. Le problème est qu'il n'y a pas de problème au début mais quand j'ouvre une nouvelle image il ne peut pas reconfigurer les anciens raccourcis. L'erreur semble indiquer qu'il essaie de configurer un séparateur au lieu d'une commande. Après avoir joué avec un peu d'impression() s, il semble que Tkinter voit les cinq premières entrées, puis saute les trois suivantes et voit toutes les autres. C'est un peu gênant avec ma tête.Problème avec un menu Tkinter en Python

Voici le code:

f=open('.recentlyUsed', 'r+') 
    f.readline() #Skipping the empty first line. 
    recents=f.read().split('\n') 
    c=0 
    recents2=[] 
    for i in recents: #Deleting the doubles. 
     if i not in recents2: 
      recents2+=[i] 
    recents=recents2[:] 
    c=0 
    while fichier.index(c)==c: #Getting the number of files already displayed in 
     c+=1      #the menu. 
     print(fichier.entryconfigure(c)) #Test : Printing the entry to know which 
    c-=7          #Tkinter sees or not. 
    if c>=0: 
     fichier.insert_separator(5)  #Doesn't insert a separator if there's no file displayed. 
    if len(recents)>=1: #If there's already a file displayed, juste modifying the label (the command doesn't need to.) 
     if c>=1: 
      fichier.entryconfigure(7, label=srecents[-1]) 
     else: 
      fichier.insert_command(6, command=lambda: openRecent(-1), label=recents[-1]) 
     if len(recents)>=2: 
      if c>=2: 
       fichier.entryconfig(8, label=recents[-2]) 
      else: 
       fichier.insert_command(6, command=lambda: openRecent(-2), label=recents[-2]) 
      if len(recents)>=3: 
       if c>=3: 
        fichier.entryconfig(9, label=.recents[-3]) 
       else: 
        fichier.insert_command(6, command=lambda: openRecent(-3), label=recents[-3]) 
       if len(recents)>=4: 
        if c>=4: 
         fichier.entryconfig(10, label=recents[-4]) 
        else: 
         fichier.insert_command(6, command=lambda: openRecent(-4), label=recents[-4]) 
        if len(recents)>=5: 
         if c>=5: 
          fichier.entryconfig(11, label=recents[-5]) 
         else: 
          fichier.insert_command(6, command=lambda: openRecent(-5), label=recents[-5]) 
    f.close() 

Et ce code renvoie les éléments suivants:

{'foreground': ('foreground', '', '', '', ''), 'accelerator': ('accelerator', '', '', '', ''), 'hidemargin': ('hidemargin', '', '', 0, 0), 'label': ('label', '', '', '', 'Nouveau'), 'underline': ('underline', '', '', -1, -1), 'bitmap': ('bitmap', '', '', '', ''), 'columnbreak': ('columnbreak', '', '', 0, 0), 'state': ('state', '', '', <index object at 0x968c230>, 'normal'), 'command': ('command', '', '', '', '3071116428nouveau'), 'background': ('background', '', '', '', ''), 'compound': ('compound', 'compound', 'Compound', <index object at 0x9689428>, 'none'), 'font': ('font', '', '', '', ''), 'image': ('image', '', '', '', ''), 'activeforeground': ('activeforeground', '', '', '', ''), 'activebackground': ('activebackground', '', '', '', '')} 
{'foreground': ('foreground', '', '', '', ''), 'accelerator': ('accelerator', '', '', '', ''), 'hidemargin': ('hidemargin', '', '', 0, 0), 'label': ('label', '', '', '', 'Ouvrir...'), 'underline': ('underline', '', '', -1, -1), 'bitmap': ('bitmap', '', '', '', ''), 'columnbreak': ('columnbreak', '', '', 0, 0), 'state': ('state', '', '', <index object at 0x968c230>, 'normal'), 'command': ('command', '', '', '', '3056134764open'), 'background': ('background', '', '', '', ''), 'compound': ('compound', 'compound', 'Compound', <index object at 0x9689428>, 'none'), 'font': ('font', '', '', '', ''), 'image': ('image', '', '', '', ''), 'activeforeground': ('activeforeground', '', '', '', ''), 'activebackground': ('activebackground', '', '', '', '')} 
{'foreground': ('foreground', '', '', '', ''), 'accelerator': ('accelerator', '', '', '', ''), 'hidemargin': ('hidemargin', '', '', 0, 0), 'label': ('label', '', '', '', 'Sauver'), 'underline': ('underline', '', '', -1, -1), 'bitmap': ('bitmap', '', '', '', ''), 'columnbreak': ('columnbreak', '', '', 0, 0), 'state': ('state', '', '', <index object at 0x968c230>, 'disabled'), 'command': ('command', '', '', '', '3056134892save'), 'background': ('background', '', '', '', ''), 'compound': ('compound', 'compound', 'Compound', <index object at 0x9689428>, 'none'), 'font': ('font', '', '', '', ''), 'image': ('image', '', '', '', ''), 'activeforeground': ('activeforeground', '', '', '', ''), 'activebackground': ('activebackground', '', '', '', '')} 
{'foreground': ('foreground', '', '', '', ''), 'accelerator': ('accelerator', '', '', '', ''), 'hidemargin': ('hidemargin', '', '', 0, 0), 'label': ('label', '', '', '', 'Sauver sous...'), 'underline': ('underline', '', '', -1, -1), 'bitmap': ('bitmap', '', '', '', ''), 'columnbreak': ('columnbreak', '', '', 0, 0), 'state': ('state', '', '', <index object at 0x968c230>, 'disabled'), 'command': ('command', '', '', '', '3056134700saveAs'), 'background': ('background', '', '', '', ''), 'compound': ('compound', 'compound', 'Compound', <index object at 0x9689428>, 'none'), 'font': ('font', '', '', '', ''), 'image': ('image', '', '', '', ''), 'activeforeground': ('activeforeground', '', '', '', ''), 'activebackground': ('activebackground', '', '', '', '')} 
{'background': ('background', '', '', '', '')} 
{'foreground': ('foreground', '', '', '', ''), 'accelerator': ('accelerator', '', '', '', ''), 'hidemargin': ('hidemargin', '', '', 0, 0), 'label': ('label', '', '', '', 'Quitter'), 'underline': ('underline', '', '', -1, -1), 'bitmap': ('bitmap', '', '', '', ''), 'columnbreak': ('columnbreak', '', '', 0, 0), 'state': ('state', '', '', <index object at 0x968c230>, 'normal'), 'command': ('command', '', '', '', '3056074828destroy'), 'background': ('background', '', '', '', ''), 'compound': ('compound', 'compound', 'Compound', <index object at 0x9689428>, 'none'), 'font': ('font', '', '', '', ''), 'image': ('image', '', '', '', ''), 'activeforeground': ('activeforeground', '', '', '', ''), 'activebackground': ('activebackground', '', '', '', '')} 
{'foreground': ('foreground', '', '', '', ''), 'accelerator': ('accelerator', '', '', '', ''), 'hidemargin': ('hidemargin', '', '', 0, 0), 'label': ('label', '', '', '', 'Quitter'), 'underline': ('underline', '', '', -1, -1), 'bitmap': ('bitmap', '', '', '', ''), 'columnbreak': ('columnbreak', '', '', 0, 0), 'state': ('state', '', '', <index object at 0x968c230>, 'normal'), 'command': ('command', '', '', '', '3056074828destroy'), 'background': ('background', '', '', '', ''), 'compound': ('compound', 'compound', 'Compound', <index object at 0x9689428>, 'none'), 'font': ('font', '', '', '', ''), 'image': ('image', '', '', '', ''), 'activeforeground': ('activeforeground', '', '', '', ''), 'activebackground': ('activebackground', '', '', '', '')} 

#Now I try oening a new image (whether by clicking on one of the shortcut to a recent picture or by the open function a defined in the project). 

{'foreground': ('foreground', '', '', '', ''), 'accelerator': ('accelerator', '', '', '', ''), 'hidemargin': ('hidemargin', '', '', 0, 0), 'label': ('label', '', '', '', 'Nouveau'), 'underline': ('underline', '', '', -1, -1), 'bitmap': ('bitmap', '', '', '', ''), 'columnbreak': ('columnbreak', '', '', 0, 0), 'state': ('state', '', '', <index object at 0x968c230>, 'normal'), 'command': ('command', '', '', '', '3071116428nouveau'), 'background': ('background', '', '', '', ''), 'compound': ('compound', 'compound', 'Compound', <index object at 0x9689428>, 'none'), 'font': ('font', '', '', '', ''), 'image': ('image', '', '', '', ''), 'activeforeground': ('activeforeground', '', '', '', ''), 'activebackground': ('activebackground', '', '', '', '')} 
{'foreground': ('foreground', '', '', '', ''), 'accelerator': ('accelerator', '', '', '', ''), 'hidemargin': ('hidemargin', '', '', 0, 0), 'label': ('label', '', '', '', 'Ouvrir...'), 'underline': ('underline', '', '', -1, -1), 'bitmap': ('bitmap', '', '', '', ''), 'columnbreak': ('columnbreak', '', '', 0, 0), 'state': ('state', '', '', <index object at 0x968c230>, 'normal'), 'command': ('command', '', '', '', <bytecode object at 0x9870a68>), 'background': ('background', '', '', '', ''), 'compound': ('compound', 'compound', 'Compound', <index object at 0x9689428>, 'none'), 'font': ('font', '', '', '', ''), 'image': ('image', '', '', '', ''), 'activeforeground': ('activeforeground', '', '', '', ''), 'activebackground': ('activebackground', '', '', '', '')} 
{'foreground': ('foreground', '', '', '', ''), 'accelerator': ('accelerator', '', '', '', ''), 'hidemargin': ('hidemargin', '', '', 0, 0), 'label': ('label', '', '', '', 'Sauver'), 'underline': ('underline', '', '', -1, -1), 'bitmap': ('bitmap', '', '', '', ''), 'columnbreak': ('columnbreak', '', '', 0, 0), 'state': ('state', '', '', <index object at 0x968c230>, 'disabled'), 'command': ('command', '', '', '', '3056134892save'), 'background': ('background', '', '', '', ''), 'compound': ('compound', 'compound', 'Compound', <index object at 0x9689428>, 'none'), 'font': ('font', '', '', '', ''), 'image': ('image', '', '', '', ''), 'activeforeground': ('activeforeground', '', '', '', ''), 'activebackground': ('activebackground', '', '', '', '')} 
{'foreground': ('foreground', '', '', '', ''), 'accelerator': ('accelerator', '', '', '', ''), 'hidemargin': ('hidemargin', '', '', 0, 0), 'label': ('label', '', '', '', 'Sauver sous...'), 'underline': ('underline', '', '', -1, -1), 'bitmap': ('bitmap', '', '', '', ''), 'columnbreak': ('columnbreak', '', '', 0, 0), 'state': ('state', '', '', <index object at 0x968c230>, 'disabled'), 'command': ('command', '', '', '', '3056134700saveAs'), 'background': ('background', '', '', '', ''), 'compound': ('compound', 'compound', 'Compound', <index object at 0x9689428>, 'none'), 'font': ('font', '', '', '', ''), 'image': ('image', '', '', '', ''), 'activeforeground': ('activeforeground', '', '', '', ''), 'activebackground': ('activebackground', '', '', '', '')} 
{'foreground': ('foreground', '', '', '', ''), 'accelerator': ('accelerator', '', '', '', ''), 'hidemargin': ('hidemargin', '', '', 0, 0), 'label': ('label', '', '', '', '/home/aquaj/workspace/projet1/lenna.pgm'), 'underline': ('underline', '', '', -1, -1), 'bitmap': ('bitmap', '', '', '', ''), 'columnbreak': ('columnbreak', '', '', 0, 0), 'state': ('state', '', '', <index object at 0x968c230>, 'normal'), 'command': ('command', '', '', '', '160341260<lambda>'), 'background': ('background', '', '', '', ''), 'compound': ('compound', 'compound', 'Compound', <index object at 0x9689428>, 'none'), 'font': ('font', '', '', '', ''), 'image': ('image', '', '', '', ''), 'activeforeground': ('activeforeground', '', '', '', ''), 'activebackground': ('activebackground', '', '', '', '')} 
{'foreground': ('foreground', '', '', '', ''), 'accelerator': ('accelerator', '', '', '', ''), 'hidemargin': ('hidemargin', '', '', 0, 0), 'label': ('label', '', '', '', '/home/aquaj/workspace/projet1/boats.pgm'), 'underline': ('underline', '', '', -1, -1), 'bitmap': ('bitmap', '', '', '', ''), 'columnbreak': ('columnbreak', '', '', 0, 0), 'state': ('state', '', '', <index object at 0x968c230>, 'normal'), 'command': ('command', '', '', '', '160341292<lambda>'), 'background': ('background', '', '', '', ''), 'compound': ('compound', 'compound', 'Compound', <index object at 0x9689428>, 'none'), 'font': ('font', '', '', '', ''), 'image': ('image', '', '', '', ''), 'activeforeground': ('activeforeground', '', '', '', ''), 'activebackground': ('activebackground', '', '', '', '')} 
{'foreground': ('foreground', '', '', '', ''), 'accelerator': ('accelerator', '', '', '', ''), 'hidemargin': ('hidemargin', '', '', 0, 0), 'label': ('label', '', '', '', '/home/aquaj/Projet_Programmation_1/Images/lena2.pgm'), 'underline': ('underline', '', '', -1, -1), 'bitmap': ('bitmap', '', '', '', ''), 'columnbreak': ('columnbreak', '', '', 0, 0), 'state': ('state', '', '', <index object at 0x968c230>, 'normal'), 'command': ('command', '', '', '', '3056177964<lambda>'), 'background': ('background', '', '', '', ''), 'compound': ('compound', 'compound', 'Compound', <index object at 0x9689428>, 'none'), 'font': ('font', '', '', '', ''), 'image': ('image', '', '', '', ''), 'activeforeground': ('activeforeground', '', '', '', ''), 'activebackground': ('activebackground', '', '', '', '')} 
{'background': ('background', '', '', '', '')} 
{'foreground': ('foreground', '', '', '', ''), 'accelerator': ('accelerator', '', '', '', ''), 'hidemargin': ('hidemargin', '', '', 0, 0), 'label': ('label', '', '', '', 'Quitter'), 'underline': ('underline', '', '', -1, -1), 'bitmap': ('bitmap', '', '', '', ''), 'columnbreak': ('columnbreak', '', '', 0, 0), 'state': ('state', '', '', <index object at 0x968c230>, 'normal'), 'command': ('command', '', '', '', '3056074828destroy'), 'background': ('background', '', '', '', ''), 'compound': ('compound', 'compound', 'Compound', <index object at 0x9689428>, 'none'), 'font': ('font', '', '', '', ''), 'image': ('image', '', '', '', ''), 'activeforeground': ('activeforeground', '', '', '', ''), 'activebackground': ('activebackground', '', '', '', '')} 
{'foreground': ('foreground', '', '', '', ''), 'accelerator': ('accelerator', '', '', '', ''), 'hidemargin': ('hidemargin', '', '', 0, 0), 'label': ('label', '', '', '', 'Quitter'), 'underline': ('underline', '', '', -1, -1), 'bitmap': ('bitmap', '', '', '', ''), 'columnbreak': ('columnbreak', '', '', 0, 0), 'state': ('state', '', '', <index object at 0x968c230>, 'normal'), 'command': ('command', '', '', '', '3056074828destroy'), 'background': ('background', '', '', '', ''), 'compound': ('compound', 'compound', 'Compound', <index object at 0x9689428>, 'none'), 'font': ('font', '', '', '', ''), 'image': ('image', '', '', '', ''), 'activeforeground': ('activeforeground', '', '', '', ''), 'activebackground': ('activebackground', '', '', '', '')} 

Exception in Tkinter callback 
Traceback (most recent call last): 
    File "/usr/lib/python3.1/tkinter/__init__.py", line 1402, in __call__ 
    return self.func(*args) 
    File "/home/aquaj/workspace/projet1/main.py", line 244, in open 
    self.recentUse(add=1) 
    File "/home/aquaj/workspace/projet1/main.py", line 307, in recentUse 
    self.fichier.entryconfig(9, label=self.recents[-3]) 
    File "/usr/lib/python3.1/tkinter/__init__.py", line 2669, in entryconfigure 
    return self._configure(('entryconfigure', index), cnf, kw) 
    File "/usr/lib/python3.1/tkinter/__init__.py", line 1187, in _configure 
    self.tk.call(_flatten((self._w, cmd)) + self._options(cnf)) 
_tkinter.TclError: unknown option "-label" 

où il devrait afficher:

{'foreground': ('foreground', '', '', '', ''), 'accelerator': ('accelerator', '', '', '', ''), 'hidemargin': ('hidemargin', '', '', 0, 0), 'label': ('label', '', '', '', 'Nouveau'), 'underline': ('underline', '', '', -1, -1), 'bitmap': ('bitmap', '', '', '', ''), 'columnbreak': ('columnbreak', '', '', 0, 0), 'state': ('state', '', '', <index object at 0x968c230>, 'normal'), 'command': ('command', '', '', '', '3071116428nouveau'), 'background': ('background', '', '', '', ''), 'compound': ('compound', 'compound', 'Compound', <index object at 0x9689428>, 'none'), 'font': ('font', '', '', '', ''), 'image': ('image', '', '', '', ''), 'activeforeground': ('activeforeground', '', '', '', ''), 'activebackground': ('activebackground', '', '', '', '')} 
{'foreground': ('foreground', '', '', '', ''), 'accelerator': ('accelerator', '', '', '', ''), 'hidemargin': ('hidemargin', '', '', 0, 0), 'label': ('label', '', '', '', 'Ouvrir...'), 'underline': ('underline', '', '', -1, -1), 'bitmap': ('bitmap', '', '', '', ''), 'columnbreak': ('columnbreak', '', '', 0, 0), 'state': ('state', '', '', <index object at 0x968c230>, 'normal'), 'command': ('command', '', '', '', <bytecode object at 0x9870a68>), 'background': ('background', '', '', '', ''), 'compound': ('compound', 'compound', 'Compound', <index object at 0x9689428>, 'none'), 'font': ('font', '', '', '', ''), 'image': ('image', '', '', '', ''), 'activeforeground': ('activeforeground', '', '', '', ''), 'activebackground': ('activebackground', '', '', '', '')} 
{'foreground': ('foreground', '', '', '', ''), 'accelerator': ('accelerator', '', '', '', ''), 'hidemargin': ('hidemargin', '', '', 0, 0), 'label': ('label', '', '', '', 'Sauver'), 'underline': ('underline', '', '', -1, -1), 'bitmap': ('bitmap', '', '', '', ''), 'columnbreak': ('columnbreak', '', '', 0, 0), 'state': ('state', '', '', <index object at 0x968c230>, 'disabled'), 'command': ('command', '', '', '', '3056134892save'), 'background': ('background', '', '', '', ''), 'compound': ('compound', 'compound', 'Compound', <index object at 0x9689428>, 'none'), 'font': ('font', '', '', '', ''), 'image': ('image', '', '', '', ''), 'activeforeground': ('activeforeground', '', '', '', ''), 'activebackground': ('activebackground', '', '', '', '')} 
{'foreground': ('foreground', '', '', '', ''), 'accelerator': ('accelerator', '', '', '', ''), 'hidemargin': ('hidemargin', '', '', 0, 0), 'label': ('label', '', '', '', 'Sauver sous...'), 'underline': ('underline', '', '', -1, -1), 'bitmap': ('bitmap', '', '', '', ''), 'columnbreak': ('columnbreak', '', '', 0, 0), 'state': ('state', '', '', <index object at 0x968c230>, 'disabled'), 'command': ('command', '', '', '', '3056134700saveAs'), 'background': ('background', '', '', '', ''), 'compound': ('compound', 'compound', 'Compound', <index object at 0x9689428>, 'none'), 'font': ('font', '', '', '', ''), 'image': ('image', '', '', '', ''), 'activeforeground': ('activeforeground', '', '', '', ''), 'activebackground': ('activebackground', '', '', '', '')} 
{'background': ('background', '', '', '', '')} 
{'foreground': ('foreground', '', '', '', ''), 'accelerator': ('accelerator', '', '', '', ''), 'hidemargin': ('hidemargin', '', '', 0, 0), 'label': ('label', '', '', '', '/home/aquaj/workspace/projet1/feuille.pgm'), 'underline': ('underline', '', '', -1, -1), 'bitmap': ('bitmap', '', '', '', ''), 'columnbreak': ('columnbreak', '', '', 0, 0), 'state': ('state', '', '', <index object at 0x968c230>, 'normal'), 'command': ('command', '', '', '', '3056177964<lambda>'), 'background': ('background', '', '', '', ''), 'compound': ('compound', 'compound', 'Compound', <index object at 0x9689428>, 'none'), 'font': ('font', '', '', '', ''), 'image': ('image', '', '', '', ''), 'activeforeground': ('activeforeground', '', '', '', ''), 'activebackground': ('activebackground', '', '', '', '')} 
{'foreground': ('foreground', '', '', '', ''), 'accelerator': ('accelerator', '', '', '', ''), 'hidemargin': ('hidemargin', '', '', 0, 0), 'label': ('label', '', '', '', '/home/aquaj/workspace/projet1/bateaux.pgm'), 'underline': ('underline', '', '', -1, -1), 'bitmap': ('bitmap', '', '', '', ''), 'columnbreak': ('columnbreak', '', '', 0, 0), 'state': ('state', '', '', <index object at 0x968c230>, 'normal'), 'command': ('command', '', '', '', '3056177964<lambda>'), 'background': ('background', '', '', '', ''), 'compound': ('compound', 'compound', 'Compound', <index object at 0x9689428>, 'none'), 'font': ('font', '', '', '', ''), 'image': ('image', '', '', '', ''), 'activeforeground': ('activeforeground', '', '', '', ''), 'activebackground': ('activebackground', '', '', '', '')} 
{'foreground': ('foreground', '', '', '', ''), 'accelerator': ('accelerator', '', '', '', ''), 'hidemargin': ('hidemargin', '', '', 0, 0), 'label': ('label', '', '', '', '/home/aquaj/workspace/projet1/lenna.pgm'), 'underline': ('underline', '', '', -1, -1), 'bitmap': ('bitmap', '', '', '', ''), 'columnbreak': ('columnbreak', '', '', 0, 0), 'state': ('state', '', '', <index object at 0x968c230>, 'normal'), 'command': ('command', '', '', '', '160341260<lambda>'), 'background': ('background', '', '', '', ''), 'compound': ('compound', 'compound', 'Compound', <index object at 0x9689428>, 'none'), 'font': ('font', '', '', '', ''), 'image': ('image', '', '', '', ''), 'activeforeground': ('activeforeground', '', '', '', ''), 'activebackground': ('activebackground', '', '', '', '')} 
{'foreground': ('foreground', '', '', '', ''), 'accelerator': ('accelerator', '', '', '', ''), 'hidemargin': ('hidemargin', '', '', 0, 0), 'label': ('label', '', '', '', '/home/aquaj/workspace/projet1/boats.pgm'), 'underline': ('underline', '', '', -1, -1), 'bitmap': ('bitmap', '', '', '', ''), 'columnbreak': ('columnbreak', '', '', 0, 0), 'state': ('state', '', '', <index object at 0x968c230>, 'normal'), 'command': ('command', '', '', '', '160341292<lambda>'), 'background': ('background', '', '', '', ''), 'compound': ('compound', 'compound', 'Compound', <index object at 0x9689428>, 'none'), 'font': ('font', '', '', '', ''), 'image': ('image', '', '', '', ''), 'activeforeground': ('activeforeground', '', '', '', ''), 'activebackground': ('activebackground', '', '', '', '')} 
{'foreground': ('foreground', '', '', '', ''), 'accelerator': ('accelerator', '', '', '', ''), 'hidemargin': ('hidemargin', '', '', 0, 0), 'label': ('label', '', '', '', '/home/aquaj/Projet_Programmation_1/Images/lena2.pgm'), 'underline': ('underline', '', '', -1, -1), 'bitmap': ('bitmap', '', '', '', ''), 'columnbreak': ('columnbreak', '', '', 0, 0), 'state': ('state', '', '', <index object at 0x968c230>, 'normal'), 'command': ('command', '', '', '', '3056177964<lambda>'), 'background': ('background', '', '', '', ''), 'compound': ('compound', 'compound', 'Compound', <index object at 0x9689428>, 'none'), 'font': ('font', '', '', '', ''), 'image': ('image', '', '', '', ''), 'activeforeground': ('activeforeground', '', '', '', ''), 'activebackground': ('activebackground', '', '', '', '')} 
{'background': ('background', '', '', '', '')} 
{'foreground': ('foreground', '', '', '', ''), 'accelerator': ('accelerator', '', '', '', ''), 'hidemargin': ('hidemargin', '', '', 0, 0), 'label': ('label', '', '', '', 'Quitter'), 'underline': ('underline', '', '', -1, -1), 'bitmap': ('bitmap', '', '', '', ''), 'columnbreak': ('columnbreak', '', '', 0, 0), 'state': ('state', '', '', <index object at 0x968c230>, 'normal'), 'command': ('command', '', '', '', '3056074828destroy'), 'background': ('background', '', '', '', ''), 'compound': ('compound', 'compound', 'Compound', <index object at 0x9689428>, 'none'), 'font': ('font', '', '', '', ''), 'image': ('image', '', '', '', ''), 'activeforeground': ('activeforeground', '', '', '', ''), 'activebackground': ('activebackground', '', '', '', '')} 
{'foreground': ('foreground', '', '', '', ''), 'accelerator': ('accelerator', '', '', '', ''), 'hidemargin': ('hidemargin', '', '', 0, 0), 'label': ('label', '', '', '', 'Quitter'), 'underline': ('underline', '', '', -1, -1), 'bitmap': ('bitmap', '', '', '', ''), 'columnbreak': ('columnbreak', '', '', 0, 0), 'state': ('state', '', '', <index object at 0x968c230>, 'normal'), 'command': ('command', '', '', '', '3056074828destroy'), 'background': ('background', '', '', '', ''), 'compound': ('compound', 'compound', 'Compound', <index object at 0x9689428>, 'none'), 'font': ('font', '', '', '', ''), 'image': ('image', '', '', '', ''), 'activeforeground': ('activeforeground', '', '', '', ''), 'activebackground': ('activebackground', '', '', '', '')} 

Donc, s'il y a quelqu'un qui peut voir où est le problème vient de ...?

Répondre

0

Cette longue chaîne de if est définitivement la mauvaise façon de le faire. Je vous suggère d'abord de supprimer toutes les anciennes entrées récentes, et d'ajouter les nouvelles à la place.

1

La solution la moins compliquée consiste simplement à recréer le menu entier à partir de zéro plutôt que d'essayer de mettre à jour certains éléments. C'est rapide, facile et presque infaillible.

Si vous décidez de rendre les éléments récents les derniers éléments du menu, vous pouvez supprimer uniquement les fichiers récents et ajouter un nouvel ensemble. C'est très facile puisque vous connaissez l'index où les fichiers récents commencent (sauf si vous avez un menu qui se développe et se rétrécit pour d'autres raisons, ce qui serait une mauvaise idée globale). Donc, n'essayez pas de mettre à jour les éléments en place, il suffit de les supprimer et de les recréer.

+0

Je l'ai fait, fonctionne parfaitement bien maintenant, merci! :) – Aquaj