PyQt5 QCalendarWidget – 通过启用来延续功能

PyQt5 QCalendarWidget – 通过启用来延续功能

在这篇文章中,我们将看到我们如何继续QCalendarWidget的功能。停止功能意味着QCalendarWidget将不能做任何事情,比如选择改变日期等等。禁用日历并不是从屏幕上删除或隐藏这个小部件。禁用是用来阻止用户在上面做任何改变,但是通过启用它将恢复所有的功能。

为了做到这一点,我们将使用QCalendarWidget对象的setEnabled方法。

语法: calendar.setEnabled(True)

参数: 它需要bool作为参数

返回: 它返回None

下面是实现方法

# importing libraries
from PyQt5.QtWidgets import *
from PyQt5 import QtCore, QtGui
from PyQt5.QtGui import *
from PyQt5.QtCore import *
import sys


class Window(QMainWindow):

    def __init__(self):
        super().__init__()

        # setting title
        self.setWindowTitle("Python ")

        # setting geometry
        self.setGeometry(100, 100, 600, 400)

        # calling method
        self.UiComponents()

        # showing all the widgets
        self.show()

    # method for components
    def UiComponents(self):

        # creating a QCalendarWidget object
        calendar = QCalendarWidget(self)

        # setting geometry to the calendar
        calendar.setGeometry(10, 10, 400, 250)

        # disabling the calendar
        calendar.setDisabled(True)

        # push button
        push = QPushButton("Enable", self)

        # setting geometry to the button
        push.setGeometry(100, 280, 100, 30)

        # adding method to it
        # inside the method enable the calendar
        push.clicked.connect(lambda: calendar.setEnabled(True))



# create pyqt5 app
App = QApplication(sys.argv)

# create the instance of our Window
window = Window()

# start the app
sys.exit(App.exec())

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

PyQt5 日历控件QCalendarWidget