Here is a part of my code, which loads images in a LabelFrame based on JSON objects from an external file. The code is inside a function (seems like that plays a role too, who knows).
# the black blackboard where images will be stored
black_background = tk.LabelFrame(pivote_tab, width=1340, height=290, bg="black")
black_background.grid(row=0, column=0, sticky="E")
# open the .json file
json_file = open('path/to/file.json', 'r')
json_data = json_file.read()
#the init position for image inside the blackboard
live_pc_position = 10
# make a loop for every object inside JSON
obj = json.loads(json_data)
for i in range(int(len(obj))):
os = (str(obj[i].get('operating_system')))
if "Mac" in os:
img_src = "image/macos_pc.png"
elif "Win" in os and "10" in os:
img_src = "image/windows_10.png"
elif "Linux" in os:
img_src = "image/linux_pc_image.png"
else:
img_src = "image/undetected_pc.png"
# defining the image based on operating system and store it to the pc_image variable
pc_image = PhotoImage(file=img_src)
# adding the computer icon inside the blackboard
computer_icon = Label(black_background, image=pc_image, bg="black")
computer_icon.place(x=live_pc_position, y=10)
# update values so the next image will load to the right
live_pc_position = live_pc_position + 40
The script doesn't make any error, however for some reason only the first image is displayed when there are more images expected to be loaded, because JSON has more objects.