This question has already been answered:
The loop reads the settings.json file with categories. Windows are created, the number of which is equal to the number of dictionaries of the array.
Buttons are created in the inner loop. Moreover, in each window, the buttons are given a specific name from the dictionary.
The problem is that only the last command name is sent to bind - thunar . That is, all buttons cause thunar .
How to fix it?
Program :
#-*-coding:utf-8-*-# from tkinter import * import json for category in json.load(open('settings.json')): topwindow = Toplevel() stuff = [] for apps in category['apps']: stuff.append(apps['command']) button1 = Button(topwindow,text=apps['name']) button1.bind("<Button-1>",lambda e: print(apps['command'])) button1.pack(fill='both') print("name: {0} command: {1}".format(apps['name'],apps['command'])) topwindow.mainloop() settings.json :
[ { "name": "Офис", "icon-name": "applications-office", "icon-size": "18", "apps": [{ "name": "Libreoffice Writer", "command": "libreoffice --writer" }, { "name": "Libreoffice Calc", "command": "libreoffice --calc" }, { "name":"Libreoffice Impress", "command":"Libreoffice --impress" } ] }, { "name": "Программирование", "icon-name": "applications-development", "icon-size": "18", "apps": [{ "name": "Sublime Text", "command": "subl" }, { "name": "Code::Blocs", "command": "codeblocks" } ] }, { "name": "Видео Аудио", "icon-name": "applications-multimedia", "icon-size": "18", "apps": [{ "name": "VLC медиаплеер", "command": "vlc" }, { "name": "Audacity", "command": "audacity" } ]}, { "name": "Интернет", "icon-name": "applications-internet", "icon-size": "18", "apps": [{ "name": "Интернет браузер", "command": "firefox" }, { "name": "Консольный интернет браузер", "command": "lynx" } ]}, { "name": "Система", "icon-name": "preferences-system", "icon-size": "18", "apps": [{ "name": "XTerm", "command": "xterm" }, { "name": "Настройки \"WP Desktop\"", "command": "wpsettings_gui --root" } ] }, { "name": "Пользователь", "icon-name": "user-home", "icon-size": "18", "apps": [{ "name": "Файловый менеджер", "command": "thunar" } ] } ]