Web Analytics Made Easy - Statcounter
Skip to content

Positioning Windows on a Multi-Monitor Setup

tkinter version of PySimpleGUI only

On the Windows operating system, it's possible to create your window on monitors other than your primary display. Think of your primary display as a single quadrant in a larger space of display area. The upper left corner of your primary display is (0,0).

If you wish to locate / create a window on the monitor to the LEFT of your primary monitor, then set the X value to a negative value. This causes the window to be created on the monitor to the left. If you set your X value to be larger than the width of your primary monitor, then you window will be created on the monitor that is located to the RIGHT of your primary monitor.]

I don't know if this technique works on Linux, but it's working great on Windows. This technique has been tried on a 4-monitor setup and it worked as you would expect.

To use this feature, rather than using the default window location of "centered on your primary screen", set the location parameter in your Window creation to be the location you wish the window to be created.

Setting the parameter location=(-500,330) in my Window call, set the location of the window on my left hand monitor.

Experimenting is the best way to get a handle on how your system responds.

It would be great to know if this works on Linux and the Mac.

This code is from a Demo Program named Demo_Window_Location_Finder.py and will help you located the x,y position on your monitors. Grab the yellow square with your mouse to move the tool around your screen. The 4 arrows point to the direction indicated

image

import PySimpleGUI as sg

sg.theme('dark green 7')

layout = [
    [sg.T(sg.SYMBOL_UP_ARROWHEAD),
     sg.Text(size=(None, 1), key='-OUT-'),
     sg.Text(size=(None, 1), key='-OUT2-', expand_x=True, expand_y=True, justification='c'), sg.T(sg.SYMBOL_UP_ARROWHEAD)],
    [sg.T('Screen size: '), sg.T(sg.Window.get_screen_size()), sg.T(sg.SYMBOL_SQUARE)],
    [sg.T(sg.SYMBOL_DOWN_ARROWHEAD),
     sg.Text(size=(None, 1), key='-OUT4-'),
     sg.Text(size=(None, 1), key='-OUT3-', expand_x=True, expand_y=True, justification='r'), sg.T(sg.SYMBOL_DOWN_ARROWHEAD, justification='r')],
]

window = sg.Window('Title not seen', layout, grab_anywhere=True, no_titlebar=True, margins=(0, 0), element_padding=(0, 0), right_click_menu=sg.MENU_RIGHT_CLICK_EDITME_EXIT,
                   keep_on_top=True, font='_ 25', finalize=True, transparent_color=sg.theme_background_color())

while True:
    event, values = window.read(timeout=100)
    if event == sg.WIN_CLOSED or event == 'Exit':
        break
    if event == 'Edit Me':
        sg.execute_editor(__file__)

    loc = window.current_location()
    window['-OUT-'].update(loc)
    window['-OUT2-'].update((loc[0] + window.size[0], loc[1]))
    window['-OUT3-'].update((loc[0] + window.size[0], loc[1] + window.size[1]))
    window['-OUT4-'].update((loc[0], loc[1] + window.size[1]))

window.close()