简体   繁体   English

如何在所有显示器上制作 tkinter 窗口全屏?

[英]How to make a tkinter window Fullscreen on all Displays?

I am working on a program with a window that needs to be fullscreen on all plugged-in Monitors and/or external displays.我正在开发一个程序,该程序的窗口需要在所有插入式监视器和/或外部显示器上全屏显示。 Is there any way I can do this in Tkinter or do I have to use a different library?有什么办法可以在 Tkinter 中做到这一点,还是必须使用不同的库? So far I have managed to get the window in Fullscreen on my main display but I also need it on the other one(s).到目前为止,我已经设法在我的主显示器上获得全屏窗口,但我在其他显示器上也需要它。 This is my code so far:到目前为止,这是我的代码:

def create_screencanvas():
    global master_screen
    master_screen = Toplevel(mywindow)
    picture_frame = Frame(master_screen, background = "blue")
    picture_frame.pack(fill=BOTH, expand=YES)

    global screenCanvas
    screenCanvas = Canvas(picture_frame, cursor="cross", bg="grey5")
    screenCanvas.pack(fill=BOTH, expand=YES)

    master_screen.attributes('-fullscreen', True)#Fullscreen on main display but not others
    master_screen.attributes('-alpha', .3)
    master_screen.lift()
    master_screen.attributes("-topmost", True)

mywindow = Tk()
mywindow.title("New Project") 
mywindow.geometry("780x640") 
mywindow.minsize(540, 420) 
mywindow.configure(bg="blue") 

mybtn = Button(text="activate", command=create_screencanvas, cursor="cross")
mybtn.pack() #Button opens the fullscrean window

mywindow.mainloop()

For screenshot taking purposes, you can make your Toplevel window cover all the displays by changing manually its geometry instead of making it fullscreen.出于截屏的目的,您可以通过手动更改其几何形状而不是使其全屏来使您的Toplevel窗口覆盖所有显示。 So, remove所以,删除

master_screen.attributes('-fullscreen', True)

and replace it with并将其替换为

w = master_screen.winfo_screenwidth()
h = master_screen.winfo_screenheight()
master_screen.geometry(f"{w}x{h}+0+0")

However, your window now has unwanted decorations.但是,您的窗口现在有不需要的装饰。 Depending on the OS you are using, you can either use根据您使用的操作系统,您可以使用

master_screen.overrideredirect(True)

or, if you are using Linux (in which case, overrideredirect might not allow you to have window transparency),或者,如果您使用的是 Linux(在这种情况下, overrideredirect可能不允许您具有窗口透明度),

master_screen.attributes('-type', 'dock')

In both cases, you no longer need在这两种情况下,您不再需要

master_screen.attributes("-topmost", True)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM