I've a data dictionary extract from my project, i want to pickup items for example at the 2nd range, from different lists as value of dictionary, i tried a method suggested by a someone in this forum "Thank u for every help!" this time i want to select items from every key start with 345##### what ever the rest #### (Note: that selected items will be at max 20) , the loop start to select item and creat a sum if did't find the key at the next position it will hold the sum, and insert it at QtableWidget cell, i tried a different way :/ any suggestion please.
import sys
from PyQt5.QtWidgets import (QWidget, QTableWidget, QHBoxLayout, QApplication, QTableWidgetItem)
from PyQt5.QtGui import QBrush, QColor
from PyQt5 import QtCore
#from FixalSolutions_build_1_3 import Ui_MainWindow
data = {'1111':['Capital 1','145321','94565','','','','74651','','','24651','','',''], '1112':['Capital 2','65115','','6149','6645','555641','','','','41245','98416','',''], '1113':['Capital 3','544453','','45345453','','555641','434556','','453453','','98416','','453453'], '1114':['Capital 4','7144453','','345453','3155485','','894556','','156453','326149','98416','',''], '1121':['Capital 5','87676','','534553','466149','','','95436','','','76745','','74568',''], '1122':['Capital 6','45645','','','47679','17345','555641','345256','','','412045','98416','',''], '1123':['Capital 7','4534453','74345','','466149','44645','1','98656','12564','','412045','98416','',''], '1124':['Capital 8','9784534','','','1326149','14553','555641','','45345','445345','412045','98416','',''], '1161': ['RAN SC', '', '', '', '32412.8', '', '32412.8', '', '', '', '', '', ''], '1162': ['Compte', '', '49850.22', '', '', '', '49850.22', '', '', '', '49850.22', '', '49850.22'], '1169': ['RAN SD', '22744.59', '', '', '', '22744.59', '', '', '', '22744.59', '', '22744.59', ''], '3455': ['item 1', '9880.4', '', '', '', '9880.4', '', '', '', '9880.4', '', '9880.4', ''], '34550200': [ 'item 2', '681.66', '', '', '', '681.66', '', '', '', '681.66', '', '681.66', ''], '34552010': [ 'item 3', '1083.87', '', '', '', '1083.87', '', '', '', '1083.87', '', '1083.87', ''], '34552020': [ 'item 4', '', '', '38026.61', '34080.67', '3945.94', '', '', '', '', '', '', ''], '34552140': [ 'item 5', '17358.79', '', '', '', '17358.79', '', '', '', '17358.79', '', '17358.79', ''], '34552200': [ 'item 6', '', '28037.7', '', '', '', '28037.7', '', '', '', '28037.7', '', '28037.7']}
class Table(QWidget):
def __init__(self, *args, parent=None):
super().__init__()
self.data = data
self.setuptUI()
def setuptUI(self):
self.setWindowTitle("QTableWidgetItem")
self.resize(1200, 800)
conLayout = QHBoxLayout()
self.tableWidget =QTableWidget(self)
self.tableWidget.setRowCount(55)
self.tableWidget.setColumnCount(14)
conLayout.addWidget(self.tableWidget)
def setdata(self, k, v, n, m):
i= 1
l = str(k*10)
item = 0
while i < i+1
if l in self.data
s = self.data.get(str(int(l)+i))[v]
i= i+1
print(item)
item = item + (int(s) if s else 0)
else:
break
self.tableWidget_Bilan.setItem(n, m, QTableWidgetItem(str(item)))
if __name__ == '__main__':
app = QApplication(sys.argv)
windows = Table(data)
windows.setdata(k="345", v=5, n=25, m=4
windows.show()
sys.exit(app.exec_())
Try it:
import sys
from PyQt5.QtWidgets import (QWidget, QTableWidget, QHBoxLayout,
QApplication, QTableWidgetItem)
from PyQt5.QtGui import QBrush, QColor
from PyQt5 import QtCore
#from FixalSolutions_build_1_3 import Ui_MainWindow
class Table(QWidget):
def __init__(self, data):
super().__init__()
self.data = data
self.setuptUI()
def setuptUI(self):
self.setWindowTitle("QTableWidgetItem")
self.resize(1200, 600)
self.tableWidget =QTableWidget(self)
self.tableWidget.setRowCount(55)
self.tableWidget.setColumnCount(14)
conLayout = QHBoxLayout(self) # + self
conLayout.addWidget(self.tableWidget)
def setdata(self, k, v, r, c):
item = 0
for kd, vd in self.data.items():
if kd[:len(k)] == k:
s = vd[v]
print("{:<10} -> `{: 10.2f}`".format(kd, float(s) if s else 0))
item = item + (float(s) if s else 0)
self.tableWidget.setItem(r, c, QTableWidgetItem(str(item)))
data = {'1111':['Capital 1','145321','94565','','','','74651','','','24651','','',''],
'1112':['Capital 2','65115','','6149','6645','555641','','','','41245','98416','',''],
'1113':['Capital 3','544453','','45345453','','555641','434556','','453453','','98416','','453453'],
'1114':['Capital 4','7144453','','345453','3155485','','894556','','156453','326149','98416','',''],
'1121':['Capital 5','87676','','534553','466149','','','95436','','','76745','','74568',''],
'1122':['Capital 6','45645','','','47679','17345','555641','345256','','','412045','98416','',''],
'1123':['Capital 7','4534453','74345','','466149','44645','1','98656','12564','','412045','98416','',''],
'1124':['Capital 8','9784534','','','1326149','14553','555641','','45345','445345','412045','98416','',''],
'1161': ['RAN SC', '', '', '', '32412.8', '', '32412.8', '', '', '', '', '', ''],
'1162': ['Compte', '', '49850.22', '', '', '', '49850.22', '', '', '', '49850.22', '', '49850.22'],
'1169': ['RAN SD', '22744.59', '', '', '', '22744.59', '', '', '', '22744.59', '', '22744.59', ''],
'3455': ['item 1', '9880.4', '', '', '', '9880.4', '', '', '', '9880.4', '', '9880.4', ''],
'34550200': [ 'item 2', '681.66', '', '', '', '681.66', '', '', '', '681.66', '', '681.66', ''],
'34552010': [ 'item 3', '1083.87', '', '', '', '1083.87', '', '', '', '1083.87', '', '1083.87', ''],
'34552020': [ 'item 4', '', '', '38026.61', '34080.67', '3945.94', '', '', '', '', '', '', ''],
'34552140': [ 'item 5', '17358.79', '', '', '', '17358.79', '', '', '', '17358.79', '', '17358.79', ''],
'34552200': [ 'item 6', '', '28037.7', '', '', '', '28037.7', '', '', '', '28037.7', '', '28037.7']}
if __name__ == '__main__':
app = QApplication(sys.argv)
windows = Table(data)
windows.setdata(k="345", v=5, r=25, c=4)
windows.show()
sys.exit(app.exec_())
I'm actually working on an image editor in Python with Tkinter (I know Python's not the best for image editing but that's for school, I didn't chose) and what I'm trying to do is saving every opened files in another file to add shortcut to the last five ones in the File menu.
The problem is that there's no problem at the start but when I open a new image it can't reconfigure the old shortcuts.
The error seems to indicate that it tries to configure a separator instead of a command. After playing with some print()s it seems that Tkinter see the first five entry then jump the next three and then see all the other.
It's kinda messin' with my head.
Here's the 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()
And this code returns the following :
{'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"
Where it should display :
{'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', '', '', '', '')}
So if there's anyone who can see where's the problem comes from... ?
The least complicated solution is to just recreate the whole menu from scratch rather than try to update certain items. It's quick, easy, and almost foolproof.
If you make the design decision to make the recent items the last items on the menu, you can delete just the recent files and append a fresh set. This is very easy since you know the index where the recent files begin unless you have a menu that grows and shrinks for other reasons.
So, don't try to update items in place, just delete and recreate.
That long chain of if's is definitely the wrong way of doing it.
I suggest you first remove all the old recent entries, and add the new ones instead.