跳转至

tkflu.entry · FluEntry 单行输入

单行输入框组件。

FluEntry 把原生 tkinter.Entry 嵌进一个圆角矩形的画布中, 从而获得 Fluent 风格的外观,同时保留原生输入框的光标、选中与输入法行为。

FluEntryCanvas

Bases: DCanvas

源代码位于: tkflu\entry.py
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
class FluEntryCanvas(DCanvas):
    draw = FluEntryDraw

    def create_round_rectangle(
        self,
        x1,
        y1,
        x2,
        y2,
        r1,
        r2=None,
        temppath=None,
        temppath2=None,
        fill="transparent",
        fill_opacity=1,
        stop1="0.93",
        stop2="0.94",
        outline="black",
        outline2="black",
        outline_opacity=1,
        outline2_opacity=1,
        width=1,
    ) -> int:
        """画输入框的圆角背景。

        :param stop1: 描边渐变的第一个 stop(输入框用的是很短的 0.93→0.94)
        :param stop2: 描边渐变的第二个 stop
        :param r1: 圆角半径(x 方向)
        :param r2: 圆角半径(y 方向)
        :param kwargs: 其余参数见
            :meth:`tkdeft.windows.canvas.DCanvas.draw_roundrect`
        :returns: 画布上的 item id

        实现转调 :meth:`tkdeft.windows.canvas.DCanvas.draw_roundrect`:
        ``stop1`` / ``stop2`` 是历史写法,tkdeft 那边统一叫
        ``gradient_stop1`` / ``gradient_stop2``,这里做一次翻译。
        """
        return self.draw_roundrect(
            x1,
            y1,
            x2,
            y2,
            r1,
            r2,
            temppath=temppath,
            temppath2=temppath2,
            stop1=stop1,
            stop2=stop2,
            fill=fill,
            fill_opacity=fill_opacity,
            outline=outline,
            outline2=outline2,
            outline_opacity=outline_opacity,
            outline2_opacity=outline2_opacity,
            width=width,
        )

    create_roundrect = create_round_rectangle

    def draw_roundrect_svg(
        self,
        x1,
        y1,
        x2,
        y2,
        radius,
        radiusy=None,
        *,
        temppath=None,
        temppath2=None,
        gradient_stop1="0.93",
        gradient_stop2="0.94",
        **kwargs,
    ) -> int:
        """SVG 兜底:输入框的描边是设计稿规定的 0.93→0.94 短渐变。"""
        self._img = self.svgdraw.create_roundrect(
            x1,
            y1,
            x2,
            y2,
            radius,
            radiusy,
            temppath=temppath,
            stop1=gradient_stop1,
            stop2=gradient_stop2,
            **kwargs,
        )
        return self.draw_svg_item(self._img, temppath2, x1, y1)

create_round_rectangle(x1, y1, x2, y2, r1, r2=None, temppath=None, temppath2=None, fill='transparent', fill_opacity=1, stop1='0.93', stop2='0.94', outline='black', outline2='black', outline_opacity=1, outline2_opacity=1, width=1)

画输入框的圆角背景。

:param stop1: 描边渐变的第一个 stop(输入框用的是很短的 0.93→0.94) :param stop2: 描边渐变的第二个 stop :param r1: 圆角半径(x 方向) :param r2: 圆角半径(y 方向) :param kwargs: 其余参数见 :meth:tkdeft.windows.canvas.DCanvas.draw_roundrect :returns: 画布上的 item id

实现转调 :meth:tkdeft.windows.canvas.DCanvas.draw_roundrect: stop1 / stop2 是历史写法,tkdeft 那边统一叫 gradient_stop1 / gradient_stop2,这里做一次翻译。

源代码位于: tkflu\entry.py
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
def create_round_rectangle(
    self,
    x1,
    y1,
    x2,
    y2,
    r1,
    r2=None,
    temppath=None,
    temppath2=None,
    fill="transparent",
    fill_opacity=1,
    stop1="0.93",
    stop2="0.94",
    outline="black",
    outline2="black",
    outline_opacity=1,
    outline2_opacity=1,
    width=1,
) -> int:
    """画输入框的圆角背景。

    :param stop1: 描边渐变的第一个 stop(输入框用的是很短的 0.93→0.94)
    :param stop2: 描边渐变的第二个 stop
    :param r1: 圆角半径(x 方向)
    :param r2: 圆角半径(y 方向)
    :param kwargs: 其余参数见
        :meth:`tkdeft.windows.canvas.DCanvas.draw_roundrect`
    :returns: 画布上的 item id

    实现转调 :meth:`tkdeft.windows.canvas.DCanvas.draw_roundrect`:
    ``stop1`` / ``stop2`` 是历史写法,tkdeft 那边统一叫
    ``gradient_stop1`` / ``gradient_stop2``,这里做一次翻译。
    """
    return self.draw_roundrect(
        x1,
        y1,
        x2,
        y2,
        r1,
        r2,
        temppath=temppath,
        temppath2=temppath2,
        stop1=stop1,
        stop2=stop2,
        fill=fill,
        fill_opacity=fill_opacity,
        outline=outline,
        outline2=outline2,
        outline_opacity=outline_opacity,
        outline2_opacity=outline2_opacity,
        width=width,
    )

draw_roundrect_svg(x1, y1, x2, y2, radius, radiusy=None, *, temppath=None, temppath2=None, gradient_stop1='0.93', gradient_stop2='0.94', **kwargs)

SVG 兜底:输入框的描边是设计稿规定的 0.93→0.94 短渐变。

源代码位于: tkflu\entry.py
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
def draw_roundrect_svg(
    self,
    x1,
    y1,
    x2,
    y2,
    radius,
    radiusy=None,
    *,
    temppath=None,
    temppath2=None,
    gradient_stop1="0.93",
    gradient_stop2="0.94",
    **kwargs,
) -> int:
    """SVG 兜底:输入框的描边是设计稿规定的 0.93→0.94 短渐变。"""
    self._img = self.svgdraw.create_roundrect(
        x1,
        y1,
        x2,
        y2,
        radius,
        radiusy,
        temppath=temppath,
        stop1=gradient_stop1,
        stop2=gradient_stop2,
        **kwargs,
    )
    return self.draw_svg_item(self._img, temppath2, x1, y1)