• PyQt4将窗口放在屏幕中间


    以下脚本显示了将窗口放在屏幕中间位置的方法。

    #!/usr/bin/python
    # -*- coding:utf-8 -*-
    
    import sys
    from PyQt4 import QtGui
    
    class Center(QtGui.QWidget):
        def __init__(self, parent = None):
            QtGui.QWidget.__init__(self, parent)
            self.setWindowTitle('moonlight poet center')
            self.resize(250, 150)
            self.center()
            
        def center(self):
            screen = QtGui.QDesktopWidget().screenGeometry()
            size = self.geometry()
            self.move((screen.width() - size.width())/2, (screen.height() - size.height())/2)
            
    app = QtGui.QApplication(sys.argv)
    center = Center()
    center.show()
    sys.exit(app.exec_())

    效果:

            self.resize(250, 150)

    该语句用来设置QWidget窗口的大小为250像素宽,150像素高。

            screen = QtGui.QDesktopWidget().screenGeometry()

    该语句用来计算显示器的分辨率(screen.width, screen.heigh)

            size = self.geometry()

    该语句用来获取QWidget窗口的大小(size.width, size.height)
            self.move((screen.width() - size.width())/2, (screen.height() - size.height())/2)

    该语句将窗口移动到屏幕的中间位置。

  • 相关阅读:
    什么是tomcat集群?
    cmd黑客入侵命令大全
    Linix基本命令
    Windows CMD命令大全
    python 函数1
    Python 集合(set)使用
    python 数据字典应用
    python 数据运算
    python 数据类型(元组(不可变列表),字符串
    python 数据类型(列表)学习笔记
  • 原文地址:https://www.cnblogs.com/moonlightpoet/p/5327242.html
Copyright © 2020-2023  润新知