简体   繁体   中英

Time picker in pyqt5

I am building an application using PyQt5 where it requires date picker and time picker. for date picker I have used QCalendarWidget whereas I'm not able to find anything for time picker. if there is something for time picker also please let me know how to use it as I want to have a popup where I can select time in hours and minutes.

Yes, Qt provides that widget. Create widget and connect it with event. In example I added label to display current value from input.

datetime = QDateTimeEdit(self)
label = QLabel("Current date & time: ", self)
datetime.dateTimeChanged.connect(lambda: dt_method())

def dt_method():
    value = datetime.dateTime()
    label.setText("Current date & time: " + str(value))

The result will be displayed in following format:

PyQt5.QtCore.QDateTime( year , month , day , hour , minutes )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM