Home > Software design >  Multiline window and list
Multiline window and list

Time:09-22

So i want in my multiline element to look something like this:

Text 1
Text 2
Text 3

But it looks like this:

{{Text 1}} {{Text 2}} {{Text 3}}

My code:

import PySimpleGUI as sg

layout_list = [
    ['Text 1'],
    ['Text 2'],
    ['Text 3']
]

layout = [
    [sg.Multiline(layout_list, s=(60, 5), disabled=True, key='key-multiline')]
]

window = sg.Window('Help!', layout=layout, margins=(1, 1))

while True:
    event, values = window.read()
    window.read()

CodePudding user response:

I managed to get it using Listbox instead of Multiline. The code is as shown below. Please note the difference that while using Listbox, the layout_list is not a list of list, rather simply a list.

import PySimpleGUI as sg                        # Part 1 - The import


layout_list = [
    'Text 1',
    'Text 2',
    'Text 3'
]

layout = [
    [sg.Listbox( values= layout_list, s=(60, 5), disabled=True, key='key-multiline')]
]

window = sg.Window('Help!', layout=layout, margins=(1, 1))

while True:
    event, values = window.read()
    window.read()

The output window is as required.

enter image description here

CodePudding user response:

Refer Curly Brackets issue in a PySimpleGui LIST box and Python 3

import PySimpleGUI as sg

layout_list = [
    ['Text 1'],
    ['Text 2'],
    ['Text 3'],
]

text = '\n'.join(item[0] for item in layout_list)    # Convert layout_list into string

layout = [
    [sg.Multiline(text, s=(60, 5), disabled=True, key='key-multiline')]
]

sg.Window('Help!', layout=layout, margins=(1, 1)).read(close=True)
  • Related