- 1 year ago
How to find current window size in pysimplegui
Comment
1 / 1
To find the current window size in PySimpleGUI, you can use the window_size
property of the sg.Window
object. Here's an example:
pythonimport PySimpleGUI as sg
# Create a window
window = sg.Window('Window Title', layout)
# Get the current window size
window_size = window.window_size()
# Extract the width and height values
width, height = window_size[0], window_size[1]
# Print the window size
print(f"Window Width: {width}, Height: {height}")
# Close the window
window.close()
In this example, window.window_size()
returns a tuple containing the width and height of the window. You can access the individual width and height values by indexing the tuple (window_size[0]
for width and window_size[1]
for height).
By printing or using the width and height values as needed, you can determine the current size of the PySimpleGUI window.