Python tkinter 屏幕宽高辅助显示 [英] Python tkinter screen width and height secondary display

查看:40
本文介绍了Python tkinter 屏幕宽高辅助显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设置了双显示器(笔记本电脑屏幕和外接显示器).我的笔记本电脑屏幕是我的主要显示器,外接显示器是次要的.两者都有不同的屏幕尺寸.

I have a dual monitors set up (laptop screen and external monitor). My laptop screen is my primary display and external monitor is secondary. Both have different screen sizes.

在我的 python tkinter 脚本中,我使用 winfo_screenwidth()winfo_screenheight() 来检测屏幕宽度和高度,以便我可以将根窗口设置为全屏.

In my python tkinter script, i have used winfo_screenwidth() and winfo_screenheight() to detect the screen width and height so that I can set the root window to become full screen.

通常,当我运行我的脚本时,根窗口将是我的笔记本电脑屏幕的大小.当我将窗口移动到扩展显示器时,我希望它自动调整宽度和高度以匹配外部显示器的宽度和高度.

Normally, when I run my script, the root window will be the size of my laptop screen. When i move the window to my extended monitor, I want it to auto adjust the width and height to match the external display's width and height.

这可能吗?有没有办法检查根窗口是在主显示还是辅助显示?

Is this possible? Is there any way to check if the root window is in primary or secondary display?

winfo_screenwidth() 是否检测辅助显示器的宽度和高度?

Does winfo_screenwidth() detect the width and height of the secondary display?

我使用的是 Windows XP Pro 32 位 &Python 2.7.

I am using Windows XP Pro 32 bit & Python 2.7.

推荐答案

我是如何做到的:

t = Tk() # new window
t.update()
t.attributes("-alpha", 00)
t.state('zoomed') # maximize the window
height= t.winfo_height() # ...
width= t.winfo_width()

但遗憾的是我不知道另一个屏幕的位置.但我认为你可以做到这一点

But sadly I do not know of the location of the other screen. But I think you can do this

  1. 创建一个新窗口
  2. 使用 winfo_screenheight() 和 winfo_screenwidth() 来了解原始屏幕
  3. 使用 geometry() 来移动窗口
  4. 最大化窗口(它应该总是在它所在的屏幕上最大化)
  5. 获取几何图形()
  6. 如果几何体在 (0, 0) 处,则它是主屏幕,继续执行 3.
  7. 您找到了另一个屏幕

这篇关于Python tkinter 屏幕宽高辅助显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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