zoukankan      html  css  js  c++  java
  • 公开课 之 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_() ) # 彻底退出
  • 相关阅读:
    [BZOJ2212][POI2011]Tree Rotations(线段树合并)
    [BZOJ3569]DZY Loves Chinese II(随机化+线性基)
    [BZOJ3237][AHOI2013]连通图(分治并查集)
    [BZOJ4945][NOI2017]游戏(2-SAT)
    [BZOJ4568][SCOI2016]幸运数字(倍增LCA,点分治+线性基)
    [BZOJ2460][BJOI2011]元素(线性基)
    [BZOJ4942][NOI2017]整数(线段树+压位)
    [P2023][AHOI2009]维护序列(线段树)
    [HDU4336]Card Collector(min-max容斥,最值反演)
    [COGS2426][HZOI 2016]几何
  • 原文地址:https://www.cnblogs.com/gdwz922/p/9123715.html
Copyright © 2011-2022 走看看