微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

收集垃圾的画布图像

如何解决收集垃圾的画布图像

我正在构建一个多帧 TK 应用程序,问题是当我为背景设置画布图像时,它正在收集垃圾

class template (Tk):

    def __init__(self,*args,**kwargs):

        Tk.__init__(self,**kwargs)

        myFrames=(startpage,identLeave)

        container = Frame(self)
        container.pack(side="top",fill="both",expand= True)
        container.grid_rowconfigure(0,weight=1)
        container.grid_rowconfigure(0,weight=1)

        self.frames = {}

        for F in myFrames:

            frame = F(container,self)
            self.frames[F] = frame
            
        
        self.show_frame(startpage)
    
    def show_frame(self,cont):
        frame= self.frames[cont]
        frame.tkraise()


class startpage(Frame):
    def __init__(self,parent,controller):

        Frame.__init__(self,parent)
        
        SetBG(parent,r'src\images\1.png')
        
        test= Button(parent,text="test").grid(row=0,column=0)

class identLeave(Frame):
    def __init__(self,parent)


app = template()
app.mainloop()

这就是我构建画布的方式

def SetBG(parent,path):

    #loading Image into system (path is relative to folder from Main.py)
    loadIMG = Image.open(path)
    img = ImageTk.PhotoImage(loadIMG)

    #setting canva with image resolution
    backg = Canvas(parent,width=1920,height=1080)
    backg.grid(sticky="nsew",columnspan=30,rowspan=30)
        
    #setting image inside the canva for display
    backg.create_image(0,image=img,ancho='nw')

    return(backg)

在类似的按钮上,我只是通过使用 button.image(img) 绕过了垃圾收集器,但在这种情况下,我无法为画布找到类似的东西。

我也对如何为应用程序设置背景图像的其他方法持开放态度

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。