请问为什么在我的Python中使用 canvas 不显示图片?
defadd_background(form):canvas=tk.Canvas(form,)image=Image.open('background.jpg')back...
def add_background(form):
canvas = tk.Canvas(form,)
image = Image.open('background.jpg')
background = ImageTk.PhotoImage(image)
canvas.create_image(0, 0, image=background, anchor="nw")
canvas.place(x=0, y=0, anchor="nw")
#form.mainloop()
def main():
form = tk.Tk()
form.geometry(300,400)
add_background(form)
form.mainloop()
if __name__ == "__main__":
main() 展开
canvas = tk.Canvas(form,)
image = Image.open('background.jpg')
background = ImageTk.PhotoImage(image)
canvas.create_image(0, 0, image=background, anchor="nw")
canvas.place(x=0, y=0, anchor="nw")
#form.mainloop()
def main():
form = tk.Tk()
form.geometry(300,400)
add_background(form)
form.mainloop()
if __name__ == "__main__":
main() 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询