Raspbery Pi 4上的两个全屏tkinter窗口位于单独的监视器上

2024-06-28 16:06:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个简单的TK应用程序,可以在一个显示器上运行全屏,但现在我想运行两个全屏窗口,一个在Raspberry Pi 4上的每个显示器上。这两个显示器有不同的分辨率,各自工作正常,但我无法让两个全屏窗口工作,两个窗口都只在第一个显示器上全屏显示

我正试图用tkinter.Tk().geometry()来做这件事,是这样做的还是有更直接的方法

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)


Tags: ontkinterwindowh1显示器cursorattributestk
1条回答
网友
1楼 · 发布于 2024-06-28 16:06:55

您必须将第二个窗口向右偏移第一个显示器的宽度(X系统首先将显示器放置在HDMI0端口上,然后将显示器从HDMI1放置到右侧)。geometry允许您确保它们不重叠,然后fullscreen按预期工作

geometry字符串的格式为:<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

相关问题 更多 >