Justify Your Text in PySimpleGUI 2020: Part 11 (Left, Center, Right)

Posted by


In PySimpleGUI 2020, you can easily justify the text within your GUI elements such as buttons, labels, input fields, and more. Justification allows you to align the text within the element to the left, center, or right of the element’s width.

In this tutorial, we will cover how to justify text within various PySimpleGUI elements using the justification parameter. Let’s get started!

  1. Justifying Text in Labels:
    Labels are a common element in GUIs used to display text. You can easily justify the text within a label using the justification parameter. Here’s an example:
import PySimpleGUI as sg

layout = [
    [sg.Text('Left Justified Text', justification='left')],
    [sg.Text('Center Justified Text', justification='center')],
    [sg.Text('Right Justified Text', justification='right')],
]

window = sg.Window('Text Justification Example', layout)
event, values = window.read()
window.close()

In the above code, we have created three labels with different justifications – left, center, and right. When you run the code, you will see the text aligned accordingly within each label.

  1. Justifying Text in Buttons:
    You can also justify the text within buttons using the justification parameter. Here’s an example:
import PySimpleGUI as sg

layout = [
    [sg.Button('Left Justified Button', justification='left')],
    [sg.Button('Center Justified Button', justification='center')],
    [sg.Button('Right Justified Button', justification='right')],
]

window = sg.Window('Button Justification Example', layout)
event, values = window.read()
window.close()

In the above code, we have created three buttons with different justifications – left, center, and right. When you run the code, you will see the text aligned accordingly within each button.

  1. Justifying Text in Input Fields:
    You can also justify the text within input fields using the justification parameter. Here’s an example:
import PySimpleGUI as sg

layout = [
    [sg.InputText('Left Justified Input', justification='left')],
    [sg.InputText('Center Justified Input', justification='center')],
    [sg.InputText('Right Justified Input', justification='right')],
]

window = sg.Window('Input Justification Example', layout)
event, values = window.read()
window.close()

In the above code, we have created three input fields with different justifications – left, center, and right. When you run the code, you will see the text aligned accordingly within each input field.

In conclusion, justifying text within PySimpleGUI elements is a simple and effective way to control the alignment of text within your GUI. Experiment with different justifications to see how they affect the appearance of your GUI elements.

0 0 votes
Article Rating

Leave a Reply

7 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@PySimpleGUI
2 hours ago

I'll be remaking this video soon.

In the process of making it, I realized that I needed to cross-post the alignment features that the tkinter port has over to PySimpleGUIQt, which is what I just now did. I'll do some additional testing, check it in, and then you'll be able to use the same parameters in Window, Column, Frame, Tab to do element alignment. It was definitely the right thing to do!

So, stay tuned and get the new version of PySimpleGUIQt soon.

@tszkincheong2820
2 hours ago

If I want to the information to the bottom_center, how should I do?

@HyperionBadger
2 hours ago

Hello, are we ever going to get documentation for PySimpleGui? Thanks!

@retvolki
2 hours ago

Hi sir., how can I possibly center a frame title? Hasn't it been implemented yet?
I've noticed all exemples in the docs have the frame title alight to the left margin.
So I've tried something like:

[sg.Frame('My Frame Title', frame_layout, font='Any 12', title_color='blue', justification='c')]

Then I get AtributeError

I've also tried putting it inside a column element but it did not work… any tips? ty!!

@Mctigerhobbes
2 hours ago

can i use justification on a Button?
Im creating the layout within a _init_ function and as soon as i use the keyword justification on a button element i get the Error: __init__() got an unexpected keyword argument 'justification'
How can I work around ?

@chrischambers5292
2 hours ago

Awesome video again…! Could I suggest you do menu bars and multi-window examples?

@graybits4111
2 hours ago

Thanks for this great software and these videos, one question please , how we can make window and/or elements display RTL instead of LTR to use for languages like Arabic,..etc

7
0
Would love your thoughts, please comment.x
()
x