this is a continuation of my previous question here. "How to add a widget to the gridlayout, starting from the upper left corner," thanks X.Jacobs to fix the tat question .. Now I want to remove all these widgets and recreate the same widgets in the same order as updating the widget library. thanks

ok this is my ui .. when i click the createPose button it calls 3 Def ..
1 . create a txt file in a specific folder
2 . clear all my widgets in my grid layout ...
3 . and finally recreate all my widgets based on the number of files and file names in a specific folder, for example, add a widget and update the library ... but in the same order as before, when it was ..
self.connect(self.ui.CreatePose_pushButton, QtCore.SIGNAL("clicked()"), self.createPose) def createPose(self):
Now I added another function to sort the folder files by creation date .. now my gridlayout arranges my buttons in the correct order .. but the position of the button jumps .. like the gap between them .. I uploaded my screenshot
source share