• 公开课 之 tony 电子时钟 (课堂笔记)


    #   tony 之电子时钟
    from PyQt5.QtWidgets import QApplication, QWidget, QLCDNumber, QDesktopWidget, QVBoxLayout
    from PyQt5.QtGui import *
    from PyQt5.QtCore import *
    import time, sys

    '''QLCDNumber 显示数字 display()
    .QDesktopWidget 测量桌面尺寸
    QVBoxLayout 承载的盒子
    '''
    # pip install PyQt5
    # 信号和槽函数

    class MyTime( QWidget ):
    '''
    1:类, 2:数据, 3:方法
    '''
    def __init__(self): # 初始化,
    super().__init__() #
    self.initUI()
    self.init_timer()



    def up_time(self): # 更新时间
    self.lcd.display( time.strftime('%X',time.localtime()) )

    def init_timer(self):
    self .timer = QTimer() # 定时器
    self.timer.setInterval( 1000 ) # 设置每1秒触发 timeout 信号
    self.timer.start() # 启动定时器
    self.timer.timeout.connect( self.up_time )

    def initUI(self): # 调整窗口组件大小,宽250px,高150px,
    self.resize( 350,220 )
    self.setWindowTitle( '斌彬电脑' ) # 标题
    self.yi_dong()

    self.lcd = QLCDNumber() # 显示组件
    self.lcd.setDigitCount( 10 ) # 要显示的数字个数,
    self.lcd.setMode( QLCDNumber.Dec ) # 显示十进制,
    self.lcd.setSegmentStyle( QLCDNumber.Flat ) # 设置平面模式
    self.lcd.display( time.strftime( '%x', time.localtime()) ) # 时间元祖 本地时间

    self.box1 = QVBoxLayout() # 构建盒子总局
    self.box1.addWidget( self.lcd ) # 要显示的放进云
    self.box1.setAlignment( Qt.AlignCenter ) # 剧中
    self.setLayout( self.box1 ) # 顶层顶层总局

    palette1 = QPalette()
    # palette1.setColor(self.backgroundRole(), QColor(192,253,123)) # 设置背景颜色
    palette1.setBrush(self.backgroundRole(), QBrush(QPixmap('1.png'))) # 设置背景图片
    self.setPalette(palette1)

    # self.yan_se.setColor( QPalette.Background.Qt.darKYellow )
    # self.setAutoFillBackground( True ) # 自动填充背景色
    # self.setPalette( self.yan_se )

    def yi_dong(self):
    m_rect = self.frameGeometry() # 设置矩
    w = QDesktopWidget().availableGeometry().center() #enter() # 获取屏幕中间
    m_rect.moveCenter( w )
    self.move( m_rect.topLeft () ) # 从左上角开始移动直到中间


    self.show() # 显示界面


    if __name__ == '__main__':
    app = QApplication( sys.argv ) # 启动
    m_time = MyTime() # 运行程序
    sys.exit( app.exec_() ) # 彻底退出
  • 相关阅读:
    web应用后台开发的故事
    XML的定义、用途、以及它的发展前景和存在的问题等等
    本学期(大三下学期)学习目标
    企业级应用与互联网应用的区别?
    新能源汽车无线充电管理网站4
    新能源汽车无线充电管理网站3
    新能源汽车无线充电管理网站2
    企业级应用与互联网应用的区别
    javaee 新学期新目标
    团队项目PCP--自我评价
  • 原文地址:https://www.cnblogs.com/gdwz922/p/9123715.html
Copyright © 2020-2023  润新知