#PyQt多显示获得分辨率,并在指定屏幕上显示
import sys
from PyQt5.QtWidgets import QApplication
ds=1 #ds代表当前显示器序号 0-主显 1-附显 2-更多显
app=QApplication(sys.argv)
widget=QWidget()
btn=QPushButton(widget)
btn.setText('Button')
btn.move(20,20)
widget.resize(800,300)
widget.setWindowTitle('show')
desk = app.desktop()
rec=desk.screenGeometry(ds)
widget.move(rec.left()+200,rec.top()+200)
h=rec.height()
w=rec.width()
print("h=",h,"w=",w)
#多屏显示2
# -*- coding: utf-8 -*-
from PyQt5.QtWidgets import QWidget,QApplication,QPushButton,QDesktopWidget
import sys
class MyWidget(QWidget):
def __init__(self):
super(MyWidget, self).__init__()
self.resize(800,600)
global btn
btn=QPushButton('退出',self)
btn.move((self.width()-btn.width())/2,(self.height()-btn.height())/2)
btn.clicked.connect(self.showMsg)
self.setWindowTitle('Title')
def getScreenNum(self):
return QApplication.desktop().screenCount()
def getRec(self,n):
a=[]
for i in range(self.getScreenNum()):
b=[]
b.append(QApplication.desktop().screenGeometry(i).width())
b.append(QApplication.desktop().screenGeometry(i).height())
a.append(b)
return a
def wSize(self,x,y):
self.resize(x,y)
btn.move((self.width()-btn.width())/2,(self.height()-btn.height())/2)
def wTitle(self,str):
self.setWindowTitle(str)
def wMove(self,num,x,y):
rec=QApplication.desktop().screenGeometry(num-1)
self.move(rec.left()+x,rec.top()+y)
def showMsg(self):
self.close()
if __name__ == '__main__':
app = QApplication(sys.argv)
win1 = MyWidget()
win1.wSize(200,200)
win1.wTitle('1')
win1.wMove(1,100,100)
win1.show()
win2 = MyWidget()
win2.wSize(400,400)
win2.wTitle('2')
win2.wMove(2,100,100)
win2.show()
win3 = MyWidget()
win3.wSize(600,600)
win3.wTitle('3')
win3.wMove(3,100,100)
win3.show()
print(win1.getRec(2))
sys.exit(app.exec_())