PyQt get date from the user

巧了我就是萌 提交于 2020-08-19 14:02:47

问题


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.

How can I do it?


回答1:


You can make it simply:

var_name = self.dateEdit.date()

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()

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

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



来源:https://stackoverflow.com/questions/8049055/pyqt-get-date-from-the-user

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!