python - 在全屏模式下的 Raspberry pi 上的背景图像上创建文本

标签 python tkinter raspberry-pi

我是新来的,所以我希望问得正确。

我想用 python 在树莓派上以全屏模式编写 GUI。我设法显示背景图像。现在我试图在上面写一个简单的文本,但我没能做到。我进行了很多搜索,但没有找到任何解决我的问题的方法。请帮忙!

这是我的代码:

from tkinter import *
from PIL import ImageTk

window = Tk()
C = canvas(window, height = 500, width=800)
C.pack()

image = ImageTk.PhotoImage(file = "home/pi/Downloads/background3.jpg")
background_label = Label(window, image = image)
background_label.place(x=0, y=0, relwidth=1, relheight=1)

Label(window, text="Hello", fg="black").pack()


window.attributes('-fullscreen', True)
windows.mainloop()

提前谢谢您!

最佳答案

您需要使用 Canvas 的create_image和create_text方法在图像上覆盖文本。只需将您的图像、所需的文本和全屏命令添加到下面的示例中即可获得您想要的内容。

from tkinter import *
from PIL import ImageTk

window = Tk()
c = Canvas(window,height=450,width=750)
image = ImageTk.PhotoImage(file="YourImage.png")
c.create_image(0,0,image=image,anchor=NW)
c.create_text(200,200,text="Hello World",fill="yellow",font="Times 32 bold")
c.pack()


window.mainloop()

关于python - 在全屏模式下的 Raspberry pi 上的背景图像上创建文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54391053/

相关文章:

python - 如何平滑对齐文本输出

python - 如何在 Python 中获取文件的 ctime 和/或 mtime,包括时区?

python - 导入适用于 Python 2.7 但不适用于 Python 3.4 的模块

Python3-ldap key 错误 : 'attributes'

python - 进度条(ttk.Progressbar)与 tkinter 中的 python 不显示

python - 新手: Yet another non-blocking delay: delay LED turn-on without sleep()

Python - 如何验证与 Fabric 模块的 SSH 连接?

Python;无法调用列表框

关闭控制台时出现 Python Matplotlib 运行时错误

python - 如何在 Raspbian Jessie 上安装 Python 3.5