PyQt 从用户那里获取日期 [英] PyQt get date from the user

查看:53
本文介绍了PyQt 从用户那里获取日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Qt Designer 中用一个按钮和一个 QDateEdit 构建了简单的小部件.用户将日期输入到 QDateEdit 中,然后当他按下按钮时,日期将被保存到一个变量中.

I built simple widget in Qt Designer with a button and a QDateEdit. The user will enter the date into the QDateEdit and then when he presses the button, the date will be saved to a variable.

我该怎么做?

推荐答案

您可以简单地:

var_name = self.dateEdit.date()

这将为您提供 QDate 格式的变量.如果您需要一种更易于使用的格式,那么您应该使用它:

This will get you a variable in QDate format. If you need it in a format which would be easier to work with then you should use this:

temp_var = self.dateEdit.date() 
var_name = temp_var.toPyDate()

第一个给你:PyQt4.QtCore.QDate(2011, 11, 8)"

The first one gives you: "PyQt4.QtCore.QDate(2011, 11, 8)"

当第二个返回时:2011-11-08"

While the second returns: "2011-11-08"

这篇关于PyQt 从用户那里获取日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆