关闭后,如何显示PyQt模式对话框并从控件中获取数据?

关闭后,如何显示PyQt模式对话框并从控件中获取数据?,第1张

关闭后,如何显示PyQt模式对话框并从控件获取数据?

这是您可以用来提示输入日期的简单类:

class DateDialog(QDialog):    def __init__(self, parent = None):        super(DateDialog, self).__init__(parent)        layout = QVBoxLayout(self)        # nice widget for editing the date        self.datetime = QDateTimeEdit(self)        self.datetime.setCalendarPopup(True)        self.datetime.setDateTime(QDateTime.currentDateTime())        layout.addWidget(self.datetime)        # OK and Cancel buttons        buttons = QDialogButtonBox( QDialogButtonBox.Ok | QDialogButtonBox.Cancel, Qt.Horizontal, self)        buttons.accepted.connect(self.accept)        buttons.rejected.connect(self.reject)        layout.addWidget(buttons)    # get current date and time from the dialog    def dateTime(self):        return self.datetime.dateTime()    # static method to create the dialog and return (date, time, accepted)    @staticmethod    def getDateTime(parent = None):        dialog = DateDialog(parent)        result = dialog.exec_()        date = dialog.dateTime()        return (date.date(), date.time(), result == QDialog.Accepted)

并使用它:

date, time, ok = DateDialog.getDateTime()


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5640250.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存