0

我正在做一个学校项目,我正在使用 Python 制作一个小游戏。在 python 中,我使用 Tkinter 接口模块来塑造它。我遇到了一个问题,我不知道如何解决它。我正在尝试在菜单中使用图像作为背景,但是对于我现在拥有的代码,它给了我一个 Unicode 错误。有谁知道它为什么给我这个?
代码:

from tkinter import *

root = Tk()
root.title("Test")
root.geometry('500x500')

background = PhotoImage(file='C:\Users\l111190\Desktop\bg.jpg')

label1 = Label(root, image=background)
label1.place (x=0, y=0)

root.mainloop()

这是我在运行时遇到的错误:

Traceback (most recent call last):
  File "D:\Informatica eindopdracht\Thonny\tkinter test scripts\tkinter test v0.2.py", line 7
    background = PhotoImage(file='C:\Users\l111190\Desktop\bg.jpg')
                                ^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
4

0 回答 0