【问题标题】:How to display window on another screen using PySimpleGui如何使用 PySimpleGui 在另一个屏幕上显示窗口
【发布时间】:2022-10-05 04:53:23
【问题描述】:

所以我有一个使用 PySimpleGUI 使用几个窗口的程序。现在,如果我要将我的窗口拖到不同的监视器上,我希望新的监视器在我将前一个窗口拖到的屏幕上弹出。我试过使用.move_to_center()get_screen_dimensions().current_location(),但我想不通。这就是我到目前为止得到的代码。 current_location 变量是前一个窗口的位置。

def correct_location(window, current_location):

screen_size = window.get_screen_dimensions()
print("Screen size: ", screen_size)
x_screen, y_screen = screen_size
print("current location: ", current_location)
x, y = current_location

if x < 0 or y < 0:
    window.move_to_center()
# if x - x_screen < 0:
#     x_screen = abs(x - x_screen)
# if y - y_screen < 0:
#     y_screen = abs(y - y_screen)
# window.move(x_screen, y_screen)
# print(window.current_location())

for monitor in screeninfo.get_monitors():
    print(monitor)
return None

输出如下:

Screen size:  (1280, 720)
current location:  (-1441, 340)
Monitor(x=-1920, y=0, width=1920, height=1080, width_mm=527, height_mm=296, name='\\\\.\\DISPLAY2', is_primary=False)
Monitor(x=-3840, y=0, width=1920, height=1080, width_mm=527, height_mm=296, name='\\\\.\\DISPLAY3', is_primary=False)
Monitor(x=0, y=0, width=1920, height=1080, width_mm=309, height_mm=174, name='\\\\.\\DISPLAY1', is_primary=True)

Process finished with exit code 0

代码背后的想法是: 如果 x 或 y 为负数 -> 这意味着它会转到另一个屏幕 -> 将窗口居中。但它一直回到主窗口中心。我认为从我迄今为止获得的数据中可以找到解决方案,但我无法弄清楚。

【问题讨论】:

    标签: python python-3.x pysimplegui


    【解决方案1】:

    这个cookbook recipe 可能有用。当然,它可能没有用。

    继续编码。记笔记。

    玩得开心。

    【讨论】:

      猜你喜欢
      • 2021-11-25
      • 1970-01-01
      • 2019-07-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-16
      • 1970-01-01
      相关资源
      最近更新 更多