python中图像顶部的标签 [英] label on top of image in python

查看:110
本文介绍了python中图像顶部的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在图像上方显示文本.现在,文本在图像下方,或者如果我在网格中放置一行= 0,该文本将消失.我假设它在图像后面.我似乎无法正常工作.我的代码是:

I am trying to display text on top of an image. Right now the text is below the image or if I put a row=0 in the grid disappears. I am assuming it is behind the image. I can't seem to get it to work. My code is:

from Tkinter import *
from PIL import ImageTk
import csv
import time

root = Tk()

image = ImageTk.PhotoImage(file='C:\Users\Shawn\PycharmProjects\Test\Background.gif')

var0 = StringVar()
var1 = StringVar()
var2 = StringVar()
var3 = StringVar()

label0 = Label(root, fg="white", textvariable=var0)
label1 = Label(root, fg="white", textvariable=var1)
label2 = Label(root, fg="white", textvariable=var2)
label3 = Label(root, fg="white", textvariable=var3)

# ----------------------------------------------------------------------
def csv_dict_reader(file_obj):
    reader = csv.DictReader(file_obj, delimiter=',')
    for column in reader:
        if (column["Week"]) == (time.strftime("%U")):
            var0.set(column["Parashat"])
            var1.set(column["Torah"])
            var2.set(column["Haftarah"])
            var3.set(column["Gospel"])

# ----------------------------------------------------------------------
if __name__ == "__main__":
    with open("Torah.csv") as f_obj:
        csv_dict_reader(f_obj)

Label(root, image=image).grid(row=0, column=0)
label0.grid()
label1.grid()
label2.grid()
label3.grid()
mainloop()

我尝试将行和列以及所有标签以及所有行和列编号放入label0.grid(row = 1,column = 1).

I have tried putting the row and column in the label0.grid(row=1, column=1), along with all labels and all row and column numbers.

我想要的结果是label0-label3居中在图像顶部.图像为黑色和深蓝色,因此白色文字会显示得很好.谢谢.

The outcome I want is label0 - label3 to be centered on top of the image. The image is black and dark blue so the white text will show well. Thank you.

肖恩

推荐答案

您可以通过将text选项添加到带有照片的标签中来实现.然后查看

You can do this by adding the text option to the label with your photo in. Then look at the compound feature to format it. It would look like this:

label=Label(image=image, text="Text", compound="center")

这篇关于python中图像顶部的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆