如何在图像标签的顶部放置文本[已解决]

时间:2020-01-06 10:12:27

标签: python-3.x tkinter

最近几天我一直在与Tkinter进行修补,以创建一个小游戏。

我已经搜索了如何在图像标签的顶部显示文本,但是有一点缺点,它不能完全显示在我正在寻找的位置(在这种情况下,标签的左上方)。 / p>

This is the current label i am working on and how it is displayed.

我在同一标签中尝试将锚和复合材料一起使用,但似乎没有任何新功能 文本仍保留在中间。

代码如下:

'''Adjusting the information frame'''
self.image_info = PhotoImage(file=locate_images("_info_panel", ""))
self.label_text_info = "• Welcome to Agony,\nto play or read the rules please go to File"
self.label_info = Label(self.info, text=self.label_text_info, font=10, image=self.image_info, compound=CENTER, anchor=NW)
self.label_info.grid(row=0, column=0)

编辑: 如果我尝试添加除compound = CENTER以外的其他任何内容,则文本将显示在指定边上图像的边界框之外。

已解决:

'''Adjusting the information frame'''
    self.image_info = PhotoImage(file=locate_images("_info_panel", ""))
    self.label_text_info = "• Welcome to Agony,\nto start the game or read the rules please go to File"
    self.canvas_info = Canvas(self.info, width=300, height=600)
    self.canvas_info.create_image((0, 0), image=self.image_info, anchor=NW)
    self.canvas_info.create_text((140, 25), text=self.label_text_info)
    self.canvas_info.grid(row=0, column=0)

我从一开始就走错了路,我对tkinter感到陌生,不得不使用画布在其中显示物品。

0 个答案:

没有答案