python pygtk如何在特定的显示器上放置一个窗口 [英] python pygtk how to put a window on a specific display monitor

查看:308
本文介绍了python pygtk如何在特定的显示器上放置一个窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在基于OS Linux的Python PyGTK库上使用(suse,ubuntu) 在具有多个显示监视器的设备上工作.

I'm using Python PyGTK library on OS Linux based (suse, ubuntu) Working on devices with multiple Display Monitors.

我正在尝试在连接到设备的特定显示监视器上放置全屏窗口(在python中,gtk.Window).

I'm trying to put a Full Screen Window (in python, gtk.Window) on a Specific Display monitor connected to the Device.

我正在使用以下代码:

n_monitors = gtk.gdk.Screen.get_n_monitors()  # Get number of monitors. 
gtk.gdk.Screen.get_monitor_geometry(*monitor_number*)  # Get the size of a specific monitor. 

第二个api返回监视器大小和偏移量信息. gtk.Window.move(offset_x, offse_y)可用于在特定监视器上移动窗口.

The second api returns the monitor size and offset information. gtk.Window.move(offset_x, offse_y) can be used for moving a window on a specific monitor.

尽管这似乎并非始终有效.看起来该窗口与鼠标位置具有相似性,或者如果显示器的分辨率不同,则无法使用.

Though this doesn't seem to work all the time. It looks like the window has an affinity to the mouse location or if the monitor resolutions are not the same this does not work.

是否有gtk.Window的任何属性可以帮助缓解此问题. 我尝试玩以下没有帮助的内容:

Is there any property of the gtk.Window which would help mitigate this issue. I tried playing with following which didn't help :

gtk.Window.set_position(gtk.WIN_POS_NONE)
gtk.Window.set_gravity(gtk.gdk.GRAVITY_NORTH_WEST)

任何想法.

推荐答案

您的监视器共同构成一个屏幕.您可以查询屏幕以了解其监视器.然后,可以通过将窗口的(x,y)设置为显示器的窗口,来将窗口放置在给定的显示器上.

Your monitors collectively form one screen. You can query a screen to find out about its monitors. You can then position your window on a given monitor by ofsetting the window's (x,y) with that of the monitor.

假设您的窗口为window,则可以得到如下所示的屏幕

Assuming your window is window, you can get the screen like this

screen = window.get_screen()

然后获取这样的监视器数据

and then get the monitor data like this

monitors = []
for m in range(screen.get_n_monitors())
  monitors.append(screen.get_monitor_geometry(m)

监视器是数字0、1、2,....如果需要,您可以获取当前监视器,如下所示:

monitors are numbers 0,1,2,... You can get the current monitor, if you need to, like this:

screen.get_monitor_at_window(screen.get_active_window())

要在监视器上放置窗口,请将监视器的(x,y)添加到窗口的(x,y).计算这些x,y值,然后移动窗口:

To position a window on a monitor, you add the monitor's (x,y) to the window's (x,y). Calculate those x,y values and then move the window:

window.move(x,y)

此处中,看到我提供的类似答案.

See a similar answer I provided here.

这篇关于python pygtk如何在特定的显示器上放置一个窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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