2011-05-20 34 views
2

我實際上正在與Tkinter一起編寫Python中的圖像編輯器(我知道Python不是圖像編輯的最佳選擇,但這是爲了學校,我沒有選擇)以及我在嘗試要做的是將每個打開的文件保存在另一個文件中,以便在文件菜單中爲最後五個文件添加快捷方式。 問題是,在開始時沒有問題,但是當我打開新圖像時,無法重新配置舊的快捷方式。 該錯誤似乎表明它嘗試配置分隔符而不是命令。在玩過一些print()之後,似乎Tkinter看到前五個條目,然後跳轉下三個,然後看到所有其他條目。 這是有點messin'我的頭。Python中的Tkinter菜單的問題

下面的代碼:

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() 

而這種代碼返回如下:

{'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" 

,它應該顯示:

{'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', '', '', '', '')} 

所以,如果有任何人誰可以看到哪來的問題來自...?

回答

0

這條長長的if的鏈肯定是這樣做的錯誤方式。 我建議你先刪除所有舊的最近條目,然後添加新的條目。

1

最簡單的解決方案是從零開始重新創建整個菜單,而不是嘗試更新某些項目。它快速,簡單,幾乎萬無一失。

如果您決定將最近的項目作爲菜單上的最後一項,您只能刪除最近的文件並添加一個新的設置。這很容易,因爲你知道最近文件開始的索引(除非你有一個菜單因其他原因而增長和縮小,這將是一個全能的壞主意)。

因此,不要試圖更新項目,只是刪除並重新創建。

+0

我已經做到了,現在工作非常好,謝謝! :) – Aquaj 2011-05-22 01:40:41