私信  •  关注

Sun Bear

Sun Bear 最近回复了

我常用的方法是将创建的按钮小部件存储在一个列表中。我修改了你的方法。见下文。

def createTags(self):

    # First create the widget and append to list variable 
    self.tags = [] #List to store button widgets
    for items in self.LoadedInstallProfiles:
        with open(items, "r") as jsonfiles:
            loadeddata = json.load(jsonfiles)
            text = loadeddata.get("profilename")
            bg = loadeddata.get("profilecolor")
            tag = Button( self.tagmenu, text=text, background=bg, command=print(text) )
            self.tag.append( tag )

    # Then display the widgets
    for tag in self.tags:
        tag.pack(side="top",fill="x")