如何跨多个监视器在 wxPython 中创建一个框架?
How to create a frame in wxPython across multiple monitors?
我正在尝试在 wxPython 中创建一个跨多个屏幕的框架。我正在尝试的设置包括一台 1366x768 的显示器和另一台 1080x1920 的纵向模式显示器。
win32api 的 GetSystemMetrics(76) 和 GetSystemMetrics(77) 结果为 0 和 -1144,以获取虚拟屏幕区域的左上角。
GetSystemMetrics(78) 和 GetSystemMetrics(79) 为我提供了 2446x1920 的总虚拟屏幕分辨率。
当我出于某种原因使用 pos = (GetSystemMetrics(76), GetSystemMetrics(77)) 和 size = (GetSystemMetrics(78), GetSystemMetrics(79)) 调用框架时,它给了我一个大小为仅第一台显示器。
import wx
from win32api import GetSystemMetrics
class SelectableFrame(wx.Frame):
c1 = None
c2 = None
def __init__(self, parent, id, title, pos, size):
wx.Frame.__init__(self, parent, id, title, pos, size, style=wx.NO_BORDER)
self.Show(True)
self.ToggleWindowStyle(wx.STAY_ON_TOP)
self.SetFocus()
self.Raise()
print(pos)
print(size)
self.Bind(wx.EVT_MOTION, self.OnMouseMove)
self.Bind(wx.EVT_LEFT_DOWN, self.OnMouseDown)
self.Bind(wx.EVT_LEFT_UP, self.OnMouseUp)
self.Bind(wx.EVT_PAINT, self.OnPaint)
self.SetCursor(wx.Cursor(wx.CURSOR_CROSS))
self.alphaValue = 100
self.SetTransparent(self.alphaValue)
self.Maximize(True)
def OnMouseMove(self, event):
global x2, y2
if event.Dragging() and event.LeftIsDown():
self.c2 = event.GetPosition()
x2 = self.c2.x
y2 = self.c2.y
self.Refresh()
def OnMouseDown(self, event):
global x1, y1
self.c1 = event.GetPosition()
x1 = self.c1.x
y1 = self.c1.y
self.Refresh()
def OnMouseUp(self, event):
print(self.c1)
print(self.c2)
self.SetCursor(wx.Cursor(wx.CURSOR_ARROW))
self.Destroy()
def OnPaint(self, event):
if self.c1 is None or self.c2 is None: return
bdc = wx.PaintDC(self)
dc = wx.GCDC(bdc)
dc.SetPen(wx.Pen('red', 1))
dc.SetBrush(wx.Brush(wx.Colour(0, 0, 0), wx.TRANSPARENT))
dc.DrawRectangle(self.c1.x, self.c1.y, self.c2.x - self.c1.x, self.c2.y - self.c1.y)
if __name__=="__main__":
app=wx.App(redirect=False)
selectionFrame2 = SelectableFrame(
parent=None,
id=wx.ID_ANY,
title="",
pos=(GetSystemMetrics(76),GetSystemMetrics(77)),
size=(GetSystemMetrics(78), GetSystemMetrics(79))
)
selectionFrame2.Show(True)
app.MainLoop()
我如何在 wxPython 中生成跨多个显示器的框架并设置它以便它可以与任何显示器组合一起工作?
wx.Display.GetCount()
# then you can get the geometry for each display
d = wx.Display(0)
d.GetGeometry()
这应该会为您提供显示器的实际大小和位置。
我正在尝试在 wxPython 中创建一个跨多个屏幕的框架。我正在尝试的设置包括一台 1366x768 的显示器和另一台 1080x1920 的纵向模式显示器。
win32api 的 GetSystemMetrics(76) 和 GetSystemMetrics(77) 结果为 0 和 -1144,以获取虚拟屏幕区域的左上角。
GetSystemMetrics(78) 和 GetSystemMetrics(79) 为我提供了 2446x1920 的总虚拟屏幕分辨率。
当我出于某种原因使用 pos = (GetSystemMetrics(76), GetSystemMetrics(77)) 和 size = (GetSystemMetrics(78), GetSystemMetrics(79)) 调用框架时,它给了我一个大小为仅第一台显示器。
import wx
from win32api import GetSystemMetrics
class SelectableFrame(wx.Frame):
c1 = None
c2 = None
def __init__(self, parent, id, title, pos, size):
wx.Frame.__init__(self, parent, id, title, pos, size, style=wx.NO_BORDER)
self.Show(True)
self.ToggleWindowStyle(wx.STAY_ON_TOP)
self.SetFocus()
self.Raise()
print(pos)
print(size)
self.Bind(wx.EVT_MOTION, self.OnMouseMove)
self.Bind(wx.EVT_LEFT_DOWN, self.OnMouseDown)
self.Bind(wx.EVT_LEFT_UP, self.OnMouseUp)
self.Bind(wx.EVT_PAINT, self.OnPaint)
self.SetCursor(wx.Cursor(wx.CURSOR_CROSS))
self.alphaValue = 100
self.SetTransparent(self.alphaValue)
self.Maximize(True)
def OnMouseMove(self, event):
global x2, y2
if event.Dragging() and event.LeftIsDown():
self.c2 = event.GetPosition()
x2 = self.c2.x
y2 = self.c2.y
self.Refresh()
def OnMouseDown(self, event):
global x1, y1
self.c1 = event.GetPosition()
x1 = self.c1.x
y1 = self.c1.y
self.Refresh()
def OnMouseUp(self, event):
print(self.c1)
print(self.c2)
self.SetCursor(wx.Cursor(wx.CURSOR_ARROW))
self.Destroy()
def OnPaint(self, event):
if self.c1 is None or self.c2 is None: return
bdc = wx.PaintDC(self)
dc = wx.GCDC(bdc)
dc.SetPen(wx.Pen('red', 1))
dc.SetBrush(wx.Brush(wx.Colour(0, 0, 0), wx.TRANSPARENT))
dc.DrawRectangle(self.c1.x, self.c1.y, self.c2.x - self.c1.x, self.c2.y - self.c1.y)
if __name__=="__main__":
app=wx.App(redirect=False)
selectionFrame2 = SelectableFrame(
parent=None,
id=wx.ID_ANY,
title="",
pos=(GetSystemMetrics(76),GetSystemMetrics(77)),
size=(GetSystemMetrics(78), GetSystemMetrics(79))
)
selectionFrame2.Show(True)
app.MainLoop()
我如何在 wxPython 中生成跨多个显示器的框架并设置它以便它可以与任何显示器组合一起工作?
wx.Display.GetCount()
# then you can get the geometry for each display
d = wx.Display(0)
d.GetGeometry()
这应该会为您提供显示器的实际大小和位置。