如何在 GTK 中检测计算机的物理屏幕大小

Dav*_*lla 11 python gtk application-development

我在编写我的应用程序时遇到了这个错误。简而言之,该应用程序的窗口大小是固定的,不适用于较小的屏幕,例如上网本。

其中,下方按钮超出屏幕限制,无法使用。我想在用户界面中考虑到这一点,但首先,我想找出在 GTK 中检测屏幕大小的标准方法是什么(如果有的话)。

那么有没有人对如何做到这一点有任何想法?

sil*_*sil 13

from gi.repository import Gdk
s = Gdk.Screen.get_default()
print(s.get_width())
print(s.get_height())
Run Code Online (Sandbox Code Playgroud)

当然,如果你有多个屏幕,这给出了包围它们的矩形的大小。这东西比听起来更难,在一个有多个屏幕的世界里......


Jus*_*tin 9

这是我想出的:

from gi.repository import Gdk, Gtk

# Replace w with the GtkWindow of your application
w = Gtk.Window()
# Get the screen from the GtkWindow
s = w.get_screen()
# Using the screen of the Window, the monitor it's on can be identified
m = s.get_monitor_at_window(s.get_active_window())
# Then get the geometry of that monitor
monitor = s.get_monitor_geometry(m)
# This is an example output
print("Heigh: %s, Width: %s" % (monitor.height, monitor.width))
Run Code Online (Sandbox Code Playgroud)

我不确定这会被称为“标准”,但我希望它有所帮助。