if i put element_justification as center i get button on the center, if i put element_justification on the right then text is also on the right even thoguht i putted justification in the text separately, i need text in center and button align to the right of the window.
import PySimpleGUI as sg layout = [[sg.Text('Nešto ne štima', text_color="", font=( 'Helvetica', 30), justification='center', key='rezultat1')], [sg.Text('Nije se spojilo na net', text_color="", font=( 'Helvetica', 20), justification='center', visible=False, key='rezultat')], [sg.Button('?', size=(0, 0), visible=True, font=( 'Helvetica', 20), key='go')], [sg.Button('Enter','center', visible=False, key='gumb')]] win = sg.Window('Proba', layout, element_justification='center') while True: e, v = win.read() if e == 'go': win.Element('rezultat').Update('Nije se spojilo na net', visible=True) if e == sg.WIN_CLOSED: win.close() break
Advertisement
Answer
There’re something about the alignment of elements.
Option
justification
insg.Text
means the alignment of multiline text in available space. So it will be nothing different if only one line and same space for it.element_justification
insg.Window
means all elements in the Window itself will have this justification if not specified.To align an element, you need more space for element to aligned, otherwise there will be nothing different. So add a
sg.Column
as container for elements to align inside of it, and setexpand_x
toTrue
to expand the space ofsg.Column
, after it, you can setelement_justification
ofsg.Column
to align the elements in it.
import PySimpleGUI as sg col_layout = [ [sg.Button('?', size=(0, 0), visible=True, font=('Helvetica', 20), key='go')], [sg.Button('Enter', visible=False, key='gumb')], # second position argument for button type, cannot use 'center' ] layout = [ [sg.Text('Nešto ne štima', text_color="", font=('Helvetica', 30), key='rezultat1')], [sg.Text('Nije se spojilo na net', text_color="", font=('Helvetica', 20), visible=False, key='rezultat')], [sg.Column(col_layout, element_justification='right', expand_x=True)], ] win = sg.Window('Proba', layout, element_justification='center') while True: e, v = win.read() if e == sg.WIN_CLOSED: break elif e == 'go': win['rezultat'].update(visible=True) win.close()
- Use
sg.Push()
/sg.VPush()
to push other elements at same/different row in horizontal/vertical direction.