简体   繁体   English

Tkinter:如何更改文本在图像上的位置

[英]Tkinter : How to change position of text on image

I have developed some application on my laptop with python and tkinter. 我在笔记本电脑上使用python和tkinter开发了一些应用程序。 Then, I was stuck at some point. 然后,我被困在某个时候。 Question is : how can I change text position on image. 问题是:如何更改图像上的文本位置。

import tkinter as tk
from PIL import Image, ImageTk

path_to_pic = "....."
root = tk.Tk()
pic = Image.open(path_to_pic)
tkpic = ImageTk.PhotoImage(pic)
tk.Label(root, image = tkpic, text = ".....", compound = tk.CENTER).pack()

root.mainloop()

This shows that my text appears on the picture, only on the center. 这表明我的文字仅出现在图片的中央。 I would like to move my text little by little and find best position. 我想一点一点地移动我的文字并找到最佳位置。 Do you know any solution or similar way to achieve this ? 您知道实现此目的的任何解决方案或类似方法吗?

You can move text horizontally and vertically by adding spaces and '\\n's respectively, to any side(s) of the text you wish: 您可以通过在想要的文本的任何一侧分别添加空格和'\\ n'来水平和垂直移动文本:

text = "caption         \n\n\n\n\n\n\n"

This will put "caption" at the top left of the text. 这会将“标题”放在文本的左上方。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM