跳转至

tkflu.text · FluText 多行文本

多行文本框组件。

FluText 与 :class:~tkflu.entry.FluEntry 类似, 把原生 tkinter.Text 嵌进圆角画布中以获得 Fluent 外观。

FluTextCanvas

Bases: DCanvas

源代码位于: tkflu\text.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
class FluTextCanvas(DCanvas):
    draw = FluTextDraw

    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 方向)
        :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 方向) :returns: 画布上的 item id

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

源代码位于: tkflu\text.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
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 方向)
    :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\text.py
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
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)