zoukankan      html  css  js  c++  java
  • PyQT5-QCalendarWidget 日历显示

     1 """
     2     QCalendarWidget:提供了日历插件
     3     Author:dengyexun
     4     DateTime:2018.11.22
     5 """
     6 from PyQt5.QtWidgets import QWidget, QCalendarWidget, QApplication, QLabel, QVBoxLayout
     7 from PyQt5.QtCore import QDate
     8 import sys
     9 
    10 class Example(QWidget):
    11 
    12     def __init__(self):
    13         super().__init__()
    14 
    15         self.initUI()
    16 
    17     def initUI(self):
    18         # 将多个控件加入到qt的布局管理器中。建立一个箱布局
    19         vbox = QVBoxLayout(self)
    20 
    21         # # 日历对象,网格可见
    22         cal = QCalendarWidget(self)
    23         cal.setGridVisible(True)
    24         # 点击日历,传入QDate数据,同showDate函数相关联
    25         cal.clicked[QDate].connect(self.showDate)
    26 
    27         # 把日历加入到这个箱子中
    28         vbox.addWidget(cal)
    29 
    30         # 显示选定的日期的label
    31         self.lbl = QLabel(self)
    32         date = cal.selectedDate()
    33         self.lbl.setText(date.toString())
    34 
    35         # 把label也加入到这个箱子中
    36         vbox.addWidget(self.lbl)
    37 
    38         # 要给vbox设置布局
    39         self.setLayout(vbox)
    40 
    41         self.setGeometry(300, 300, 350, 300)
    42         self.setWindowTitle('Calendar')
    43         self.show()
    44 
    45     def showDate(self, date):
    46         """
    47         显示选中的日期
    48         :param date: 点击日历组件,接收传入的参数
    49         :return:
    50         """
    51         self.lbl.setText(date.toString())
    52 
    53 
    54 if __name__ == '__main__':
    55     app = QApplication(sys.argv)
    56     ex = Example()
    57     sys.exit(app.exec_())
  • 相关阅读:
    Sprinig.net 双向绑定 Bidirectional data binding and data model management 和 UpdatePanel
    Memcached是什么
    Spring.net 网络示例 codeproject
    jquery.modalbox.show 插件
    UVA 639 Don't Get Rooked
    UVA 539 The Settlers of Catan
    UVA 301 Transportation
    UVA 331 Mapping the Swaps
    UVA 216 Getting in Line
    UVA 10344 23 out of 5
  • 原文地址:https://www.cnblogs.com/demo-deng/p/10007229.html
Copyright © 2011-2022 走看看