如何使用Tkinter在辅助显示中使窗口全屏显示? [英] How to make a window fullscreen in a secondary display with tkinter?

查看:307
本文介绍了如何使用Tkinter在辅助显示中使窗口全屏显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何在主"屏幕上全屏显示窗口,但是即使在我将应用程序的窗口移动到连接到PC的辅助显示器上时,我也会调用:

I know how to make a window fullscreen in the "main" display, but even when moving my app's window to a secondary display connected to my PC, when I call:

self.master.attributes('-fullscreen', True)

要以全屏方式显示该窗口,它会在主"显示中而不是在辅助窗口中显示(该应用程序的窗口将从辅助显示中消失,并立即以全屏方式出现在主"显示中).

to fullscreen that window, it does so in the "main" display and not in the secondary one (the app's window disappears from the secondary display and instantly appears in the "main" one, in fullscreen).

如何在辅助显示屏上将其全屏显示?

How can I make it fullscreen in the secondary display?

推荐答案

在Windows 7上有效:如果第二个屏幕的宽度和高度与第一个相同,则可以使用以下代码的win1或win2几何图形,具体取决于它的相对位置(leftof或rightof)以在辅助显示中全屏显示:

This works on Windows 7: If the second screen width and height are the same as the first one, you can use win1 or win2 geometry of the following code depending its relative position(leftof or rightof) to have a fullscreen in a secondary display:

from Tkinter import *

def create_win():
    def close(): win1.destroy();win2.destroy()
    win1 = Toplevel()
    win1.geometry('%dx%d%+d+%d'%(sw,sh,-sw,0))
    Button(win1,text="Exit1",command=close).pack()
    win2 = Toplevel()
    win2.geometry('%dx%d%+d+%d'%(sw,sh,sw,0))
    Button(win2,text="Exit2",command=close).pack()

root=Tk()
sw,sh = root.winfo_screenwidth(),root.winfo_screenheight()
print "screen1:",sw,sh
w,h = 800,600 
a,b = (sw-w)/2,(sh-h)/2 

Button(root,text="Exit",command=lambda r=root:r.destroy()).pack()
Button(root,text="Create win2",command=create_win).pack()

root.geometry('%sx%s+%s+%s'%(w,h,a,b))
root.mainloop()

这篇关于如何使用Tkinter在辅助显示中使窗口全屏显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆