如何更改标签窗口小部件中文本的位置?

时间:2019-09-24 02:27:57

标签: python tkinter label

我想在背景图片上添加标题,代码为

from tkinter import *
root = Tk()
photo = PhotoImage(file = 'a.gif')
Label(root,text='Life is short \n you need python',image=photo, fg = 'red',\
  compound = CENTER,font = ('Times Newman',20)).pack()
root.mainloop()

获取此 CODE result shortcut

但是我无法更改文本的位置,我想将文本移到顶部,就像图像中标记的箭头一样。

谢谢,帮助!

1 个答案:

答案 0 :(得分:0)

谢谢您的关注,我发表了我的回答。我尝试了Label和pack的所有参数,但是没有用,因为参数被设置为移动除文本标签之外的所有标签,“ font”参数除外。 因此,如果要在带有背景图像的Label上移动文本,而将“ compound”设置为“ CENTER”,则应将CODE重写为

from tkinter import *
txt = 'Life is short \n you need python \n\n\n\n\n' # just add some \n
root = Tk()
photo = PhotoImage(file = 'a.gif')
Label(root,text=txt,image=photo, fg = 'red',compound = CENTER,font = ('Times Newman',20)).pack()
root.mainloop()

NEW CODE results

相关问题