简体   繁体   English

Python tkinter屏幕宽度和高度辅助显示

[英]Python tkinter screen width and height secondary display

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. 两者都有不同的屏幕尺寸。

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. 在我的python winfo_screenwidth()脚本中,我使用了winfo_screenwidth()winfo_screenheight()来检测屏幕宽度和高度,以便我可以将根窗口设置为全屏。

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? 有没有办法检查根窗口是在主显示器还是辅助显示器?

Does winfo_screenwidth() detect the width and height of the secondary display? winfo_screenwidth()是否检测到辅助显示的宽度和高度?

EDIT: I am using Windows XP Pro 32 bit & Python 2.7. 编辑:我使用的是Windows XP Pro 32位和Python 2.7。

How I did it: 我是怎么做到的

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. create a new window 创建一个新窗口
  2. use winfo_screenheight() and winfo_screenwidth() to find out about the original screen 使用winfo_screenheight()和winfo_screenwidth()来查找原始屏幕
  3. use geometry() to move the window around 使用geometry()移动窗口
  4. maximize the window (it should always maximize at the screen where it is) 最大化窗口(它应始终在屏幕上最大化)
  5. get geometry() 获得几何()
  6. if geometry is at (0, 0) it is the main screen, proceed with 3. 如果几何是(0,0)它是主屏幕,继续3。
  7. you found another screen 你找到了另一个屏幕

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

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