我如何将json文件名(不带扩展名)加载到列表框和组合框(python)中?

问题描述 投票:-1回答:2

我需要从文件夹中导入json文件作为列表框中的项目,然后再导入组合框。我尝试使用以下方法将文件加载到列表框中:

path_to_json = './'
json_files = [pos_json for pos_json in os.listdir(path_to_json) if pos_json.endswith('.json')]
self.profiles_print(json_files)

i可以将文件加载到列表框中,但是它们全部作为一项加载在一行上。

如何将其制成单个物品?

谢谢,Dom

python json tkinter listbox
2个回答
0
投票

您的代码看起来正确,但是我不了解self.profiles_print的逻辑,这似乎是一个难题,您可以显示代码吗?


0
投票

从其他来源回答:

path_to_json = './'
    json_files = [pos_json for pos_json in os.listdir(path_to_json) if pos_json.endswith('.json')]
    for i in json_files:
        self.profiles_print(i)
© www.soinside.com 2019 - 2024. All rights reserved.