I have a simple TK app that runs fullscreen just fine on one monitor, but now I want to run two fullscreen windows, one on each display on a Raspberry Pi 4. The two displays have different resolutions and work fine on their own, but I can’t get two fullscreen windows to work, both windows fullscreen just on the first display.
I’m trying to do it with tkinter.Tk().geometry()
, is this the way to go or is there something more straightforward?
import tkinter root = tkinter.Tk() # specify resolutions of both windows w0, h0 = 3840, 2160 w1, h1 = 1920, 1080 # set up window for display on HDMI 0 win0 = tkinter.Toplevel() win0.geometry(f"{w0}x{h0}") win0.attributes("-fullscreen", True) win0.config(cursor="none") # remove cursor win0.wm_attributes("-topmost", 1) # make sure this window is on top # set up window for display on HDMI 1 win1 = tkinter.Toplevel() win1.geometry(f"{w1}x{h1}") win1.attributes("-fullscreen", True) win1.config(cursor="none") win1.wm_attributes("-topmost", 1)
Advertisement
Answer
You have to offset the second window to the right by the width of the first display (The X system puts the display on the HDMI0
port down first, then puts the display from HDMI1
to the right).geometry
lets you make sure they don’t overlap and then fullscreen
works as expected.
The format of the geometry
string is: <width>x<height>+xoffset+yoffset
.
root = tkinter.Tk() # specify resolutions of both windows w0, h0 = 3840, 2160 w1, h1 = 1920, 1080 # set up window for display on HDMI 0 win0 = tkinter.Toplevel() win0.geometry(f"{w0}x{h0}+0+0") win0.attributes("-fullscreen", True) # set up window for display on HDMI 1 win1 = tkinter.Toplevel() win1.geometry(f"{w1}x{h1}+{w0}+0") # <- the key is shifting right by w0 here win1.attributes("-fullscreen", True) root.withdraw() # hide the empty root window