PySimpleGUI #3 Window Style

Posted by


PySimpleGUI is a python library that allows you to easily create graphical user interfaces (GUI) for your python applications. In this tutorial, we will focus on how to style the windows created using PySimpleGUI.

To start, you’ll need to install the PySimpleGUI library if you haven’t already. You can do this by running the following command in your terminal or command prompt:

pip install PySimpleGUI

Now that you have PySimpleGUI installed, let’s create a basic window using PySimpleGUI and customize its appearance.

import PySimpleGUI as sg

layout = [
    [sg.Text('Hello, World!')],
    [sg.Button('Ok')]
]

window = sg.Window('My First PySimpleGUI Window', layout)

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

    if event == sg.WIN_CLOSED or event == 'Ok':
        break

window.close()

This code creates a simple window with a text element displaying "Hello, World!" and a button labeled "Ok". The window will close when the user clicks the "Ok" button or closes the window.

Now, let’s move on to styling the window. PySimpleGUI provides a set of predefined styles that you can use to customize the appearance of your windows. You can set the style of a window by adding the set_options method to the sg.Window call.

Here’s an example of how you can set the style of the window to a predefined theme called ‘Reddit’:

window = sg.Window('My First PySimpleGUI Window', layout, set_options={'background_color': '#FF0000'})

In this example, we set the background color of the window to red. You can customize the appearance of your window further by using different predefined styles or by specifying custom options.

For example, you can set the font, text color, button color, and more by setting the respective options in the set_options method. Here’s an example of how you can set the font of the text element to a different font:

layout = [
    [sg.Text('Hello, World!', font=('Arial', 18))],
    [sg.Button('Ok')]
]

In this example, we set the font of the text element to Arial with a size of 18. You can experiment with different options to achieve the look you desire for your windows.

In conclusion, PySimpleGUI allows you to easily create and style windows for your python applications. By using the set_options method, you can customize the appearance of your windows in various ways. Experiment with different styles and options to create windows that match the design of your application.

0 0 votes
Article Rating

Leave a Reply

4 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@alexzshow6314
3 hours ago

Благодарю за информацию все здорово и подробно объяснено, но можно ли узнать есть ли в данном модуле возможность делать прозрачный только background у окна не трогая прозрачность элементов?

@Kersmaik
3 hours ago

Очень приятно впитывать информацию, спасибо!

@devZu9
3 hours ago

После того как я создал приложение использую PyQT, поплевавшись с Tkinter, встретив заморочки с использованием wxPython и даже попробовав Eel, я стал смотреть на эту демонстрацию и реально чуть не кончил. Блин ну это же надо так всё просто то. Надеюсь, что дальше уроки не разочаруют, потому что по ощущениям это именно тот инструмент, который я очень долго искал.

@GameChannelOfficial
3 hours ago

Блин, подача топ только вот белый цвет редактора кода в глаза колит, не удобно вообще чекать чу там происходит такое ощущение будто бы в 2011 году видос вышел

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