0

enter image description hereI have used tkinter to organize pictures with text inside various frames on a canvas with a scrollbar. (as can be seen in the picture). I'm really struggling to achieve same functionalities with pysimplegui. I need help on creating a layout using Image(),Text() and Frame() Elements. I have also tried to manipulate the layout with Column Element without success. Looping through the arrangement really stops my progress.

2
  • Tell us more, it looks like that there's nothing about your project and your problem. Commented Dec 29, 2024 at 16:19
  • I'm unsure whether the picture was included or not Commented Dec 29, 2024 at 17:51

1 Answer 1

1

To avoid the location issue for image and text, I build a Image Column for it.

If you need to work dynamically with adding elements, Image, Frame, remember to call window.refresh() and scrollable_column.contents_changed() after it, so it will update all content to keep the scroller work correctly.

Example Code

import PySimpleGUI as sg

class Image(sg.Column):

    def __init__(self, source, text):
        layout = [[sg.Image(source)], [sg.Text(text, size=8, justification="center")]]
        super().__init__(layout, element_justification="center")

sg.theme("DarkBlue")
sg.set_options(font=("Courier New", 11))

emoji = {"Happy":sg.EMOJI_BASE64_HAPPY_LIST, "SADLY":sg.EMOJI_BASE64_SAD_LIST}

columns = 10
column_layout = []
for title, lst in emoji.items():
    frame_layout, line = [], []
    limit = len(lst) - 1
    for i, item in enumerate(lst):
        line.append(Image(item, f"{title} {i+1}"))
        if i % columns == columns - 1 or i == limit:
            frame_layout.append(line)
            line = []
    column_layout.append([sg.Frame(title, frame_layout)])

layout = [[sg.Column(column_layout, scrollable=True, vertical_scroll_only=True)]]
sg.Window("Scrollable Frames with Images", layout).read(close=True)

enter image description here

Sign up to request clarification or add additional context in comments.

6 Comments

The emoji dictionary has two keys and values given in two lists with 36 and 29 elements respectively. Can the dictionary be built using loops, say keys in some range and list with various length? The list should preferably be nested such that values in row 1 belongs to key 1 or in general row number x in the nested loop belongs to key number x
Of course, you can build the nested figure lists and key list. for example: keys = ["Happy", "SAD"]; lists = [sg.EMOJI_BASE64_HAPPY_LIST, sg.EMOJI_BASE64_SAD_LIST] and loop them by for title, lst in zip(keys, lists):.
I manage to create a dictionary in this way:
my_dict = {serie_names[i]: img_file[i] for i in range(len(serie_names))} It should have worked days ago, but due to a bug in file name which i
or my_dict = {name:files for name, files in zip(serie_names, img_file)}
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.