tkinter canvas create_text size (python3)

谁说胖子不能爱 提交于 2021-01-29 06:20:59

问题


I understand that it is possible to get the size of text on a canvas:

t = canvas.create_text(x, y, text='Hello StackOverflow')
print(canvas.bbox(t))

but I want to decide where to draw the text based on its size, so I need to know the size before the text is drawn. How to do that?


回答1:


A possible solution is

tk.font.Font(size=9, family='Helvetica').measure('HelloStackoverflow')



回答2:


Use that line of code.

canvas.create_text(245,100, fill = 'red', font = "Times 20 italic bold", text = "Hello StackOverflow" )

Here 245,100 is the center of the text box.

fill = 'red' it is text color

font = "Times 20 italic bold" # text size is 20 pixel and it is italic font.



来源:https://stackoverflow.com/questions/53449660/tkinter-canvas-create-text-size-python3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!