2021-01-07

#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_())

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值