python库“urwid”是否包含用于读取日期的小部件(datepicker)?

2024-09-30 06:18:55 发布

您现在位置:Python中文网/ 问答频道 /正文

npyscreen具有用于选择日期的小部件"DateCombo" and "TitleDateCombo"。在

乌尔韦德有什么相似之处吗? 如果没有,是否有推荐的第三方库?在

下面是一个使用npyscreen的示例:

enter image description here

#! /usr/bin/env python3
# -*- coding: utf-8 -*-

import npyscreen

class DateForm(npyscreen.Form):
    def afterEditing(self):
        self.parentApp.setNextForm(None)

    def create(self):
        self.date = self.add(npyscreen.TitleDateCombo, name="Date")

class TestApplication(npyscreen.NPSAppManaged):
    def onStart(self):
        new_user = self.addForm("MAIN", DateForm, name="Read Date")

if __name__ == "__main__":
    TestApplication().run()

Tags: andnameself示例datebin部件usr
2条回答

python库^{}似乎没有包含日期选择器(stateof2018)。所以我写了一篇(初步的)文章。在

这个类叫做^{},并且可以通过pip安装。在

Demonstration of date picker #1Demonstration of date picker #2


有关说明小部件功能的独立示例,请参见here。在

如需更多(更简单)的示例,请参阅here。在

有关参数和选项的详细说明,请参见the corresponding github wiki entry。在



一些例子

最小

#! /usr/bin/env python3
# -*- coding: utf-8 -*-

from additional_urwid_widgets import DatePicker, MODIFIER_KEY      # installed via pip
import urwid                                                       # installed via pip

# Color schemes that specify the appearance off focus and on focus.
PALETTE = [("reveal_focus", "black", "white")]

dp = DatePicker(highlight_prop=("reveal_focus", None))        # By default, the focused picker is not highlighted!

pile = urwid.Pile([urwid.Text("press additionally the key modifier (default is 'ctrl')."),
                   urwid.Divider(" "),
                   dp])

loop = urwid.MainLoop(urwid.Filler(pile, "top"),
                      PALETTE)
loop.run()

Demonstration of example 'Minimal'


今天不是

^{pr2}$

Demonstration of example 'Not today'


ISO-8601+样式+紧凑型

#! /usr/bin/env python3
# -*- coding: utf-8 -*-

import calendar
from additional_urwid_widgets import DatePicker, MODIFIER_KEY      # installed via pip
import urwid                                                       # installed via pip

# Color schemes that specify the appearance off focus and on focus.
PALETTE = [("dp_barActive_focus",       "light gray",       ""),
           ("dp_barActive_offFocus",    "black",            ""),
           ("dp_barInactive_focus",     "dark gray",        ""),
           ("dp_barInactive_offFocus",  "black",            ""),
           ("dp_highlight_focus",       "black",            "brown",   "standout"),
           ("dp_highlight_offFocus",    "white",            "black")]

dp = DatePicker(month_names=[str(i).zfill(2) for i in range(13)],
                day_format=[DatePicker.DAY_FORMAT.DAY_OF_MONTH_TWO_DIGIT],
                columns=((6, DatePicker.PICKER.YEAR), (4, DatePicker.PICKER.MONTH), (4, DatePicker.PICKER.DAY)),
                min_width_each_picker=4,
                space_between=1,
                topBar_endCovered_prop=("ᐃ", "dp_barActive_focus", "dp_barActive_offFocus"),
                topBar_endExposed_prop=("───", "dp_barInactive_focus", "dp_barInactive_offFocus"),
                bottomBar_endCovered_prop=("ᐁ", "dp_barActive_focus", "dp_barActive_offFocus"),
                bottomBar_endExposed_prop=("───", "dp_barInactive_focus", "dp_barInactive_offFocus"),
                highlight_prop=("dp_highlight_focus", "dp_highlight_offFocus"))

pile = urwid.Pile([urwid.Text("press additionally the key modifier (default is 'ctrl')."),
                   urwid.Divider(" "),
                   dp])

loop = urwid.MainLoop(urwid.Filler(pile, "top"),
                      PALETTE)
loop.run()

Demonstration of example 'ISO-8601 + Styled + Compact'

不,urwid没有日期选择器,它是一个复杂的小部件,需要自己的项目来实现,因为这些小部件通常需要考虑日期格式、区域设置等

我不知道任何实现它的urwid库,并且通过快速扫描我知道的库也找不到。在

您可以尝试购买一个库,但您可能会有更好的运气实现一个自己的具体需要。在

相关问题 更多 >

    热门问题