【发布时间】:2020-04-14 22:53:48
【问题描述】:
目前,我正在创建一个文字冒险游戏。现在,为了让它比许多使用 python 控制台的软件好一点,我正在使用 Tkinter 来制作 GUI。只有它显示我的开始屏幕的背景图像,而不是我放在那里的文本!请帮忙!
# writes the title as text in the window
titleFont = tkFont.Font(family = "Comic Sans MS", size = 20)
titleText = tkinter.Label(app, text="Gods of This World", font=titleFont)
titleText.pack()
# sets the background image to the games 3 colors (Red, Green, Grey)
C = tkinter.Canvas(app, height=300, width=250)
filename = tkinter.PhotoImage(file = "C:/Users/" + getpass.getuser() + "/Desktop/Gods of This World/net/godsofthisworld/ui/images/backgroundimage.png")
background_label = tkinter.Label(app, image=filename)
background_label.place(x=0, y=0, relwidth=1, relheight=1)
C.pack()
【问题讨论】:
-
首先运行
titleText.pack(),然后运行background_label.place(),这样它就可以将image放在text之上——你的text可以隐藏在image后面。把它放在不同的顺序。 BTW:如果你不使用canvas.create_image()和canvas_create_text(),我不知道你为什么要创建Canvas -
好的等等,别介意我用画布添加文本,这样它就不会用灰色背景覆盖我的图像。