如何編輯畫布中文本的 x 和 y 位置
from tkinter import *
tk = Tk()
canvas = Canvas(tk, width=100, height=100, bd=0, highlightthickness=0)
p = canvas.create_text(width/2, height/2, text = '', anchor="center", justify='center', fill="white", font = ("Arial", int(80/(0.371428571 * size))))
我可以用它來編輯文本:
canvas.itemconfigure(p, text=currentTime "\n" tempDate)
canvas.itemconfigure(p, anchor="center")
canvas.itemconfigure(p, justify='center')
但我不知道如何配置 x 和 y 的值(這是在我做的時候設定的(寬度/2,高度/2)。我希望能夠將 x 和 y 更改為畫布的新中心它增加了(以便文本保留在中心)如果我知道如何更改 x 和 y,我可以做到
諸如 __X 或 __Y 或 coords 或 __coords 或 x 或 y 之類的東西在 itemconfigure 中不起作用并給了我一個錯誤
這是它應該采取的:
(method)
create_text(__x: float, __y: float, *, activefill: _Color = ..., activestipple: str = ..., anchor: _Anchor = ..., disabledfill: _Color = ..., disabledstipple: _Bitmap = ..., fill: _Color = ..., font: _FontDescription = ..., justify: Literal['left', 'center', 'right'] = ..., offset: _ScreenUnits = ..., state: Literal['normal', 'active', 'disabled'] = ..., stipple: _Bitmap = ..., tags: _TkinterSequence[str] | str = ..., text: float | str = ..., width: _ScreenUnits = ...) -> _CanvasItemId
uj5u.com熱心網友回復:
您可以簡單地使用canvas.moveto(p, x, y)where (x, y) 是您想要的位置。
或者canvas.coords(p, x, y)保留anchor選項。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/331312.html
下一篇:用U2Net去除背景的力度太大
