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_() ) # 彻底退出
  • 相关阅读:
    word20170108逛景点 Sightseeing有用的词和句子
    c# List 分页问题
    VUE界面,this.form.xxx=1赋值后,界面效果没有变化
    SQL Server使用索引视图来实现“物化视图”
    .NET CORE 实现异步处理
    当请求接口提示网络错误Error:Network Error的时候
    SheetJS js-xlsx :js实现导出Excel模板
    增加索引分析
    聚集索引与非聚集索引的总结
    Dynamics CRM-无法识别安全令牌的颁发者,若要接受来自此颁发者的安全令牌,请将 IssuerNameRegistry 配置为返回此颁发者的有效名称
  • 原文地址:https://www.cnblogs.com/gdwz922/p/9123715.html
Copyright © 2011-2022 走看看