I use image (and button) as so:
JavaScript
x
7
1
myImg = sg.Image(filename='off.png', key='_CAMIMAGE_')
2
3
layout1 = [[myImg],
4
[sg.Button('Exit')]]
5
6
sg.Window(title="Lights", layout=layout1, size=(500,300), margins=(0, 0)).read()
7
How do I align the myImg to center? I tried google can’t find anything on how to do it. I read somebody suggested justification=’center’ but I don’t know where to put that. I tried [myImg, justification=’center’] didn’t work just crash the app.
Advertisement
Answer
Based on documentation you can use Column with justification='center'
to center widgets.
It needs list of rows – like [[my_img]]
But it centers column
in window
, not widgets
in column
so for row with Button
it can need separated Column
.
JavaScript
1
18
18
1
import PySimpleGUI as sg
2
3
my_img = sg.Image(filename='rgb.png', key='_CAMIMAGE_')
4
5
# doesn't center Button in Columns
6
#layout = [
7
# [sg.Column([[my_img], [sg.Button('Exit')]], justification='center')],
8
#]
9
10
layout = [
11
[sg.Column([[my_img]], justification='center')],
12
[sg.Column([[sg.Button('Exit')]], justification='center')],
13
]
14
15
window = sg.Window(title="Lights", layout=layout, size=(500, 500), margins=(0, 0))
16
window.read()
17
window.close()
18
BTW:
justification='center'
can be used also in Text
to center text.