2011-05-20 35 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