我正在尝试为tkinter
应用添加背景信息。出于某种原因,当我使用类继承时,我无法使其工作:
import tkinter as tk
class App(tk.Tk):
def __init__(self):
super().__init__()
C = tk.Canvas(self, bg="blue", height=0, width=0)
filename = tk.PhotoImage(file='bg.png')
background_label = tk.Label(self, image=filename)
background_label.place(x=0, y=0, relwidth=1, relheight=1)
C.pack()
self.geometry('400x200')
app = App()
app.mainloop()
但如果我这样做:
import tkinter as tk
top = tk.Tk()
C = tk.Canvas(top, bg="blue", height=0, width=0)
filename = tk.PhotoImage(file='bg.png')
background_label = tk.Label(top, image=filename)
background_label.place(x=0, y=0, relwidth=1, relheight=1)
C.pack()
top.geometry('200x200')
top.mainloop()
它完美无缺。知道我错过了什么吗?