Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def create_accordion_widget_list(self, treelist):
acf = AccordionFrame(self.widgetlist)
acf.grid(sticky=tk.NSEW)
acf.bind('<>', self.on_widgetlist_group_toogle)
#Default widget image:
default_image = ''
try:
default_image = StockImage.get('22x22-tk.default')
except StockImageException as e:
pass
#Start building widget tree selector
roots = {}
sections = {}
for key, wc in treelist:
root, section = key.split('>')
#insert root
try:
default_image = StockImage.get('22x22-tk.default')
except StockImageException as e:
pass
#Start building widget tree selector
roots = {}
sections = {}
for key, wc in treelist:
root, section = key.split('>')
#insert root
if root not in roots:
roots[root] = acf.add_group(root, root)
#insert section
if key not in sections:
sectionacf = AccordionFrame(roots[root])
sectionacf.grid(sticky=tk.NSEW, padx='5 0')
sectionacf.bind('<>',
self.on_widgetlist_group_toogle)
sectiongrp = sectionacf.add_group(key, section)
sections[key] = AutoArrangeFrame(sectiongrp)
sections[key].grid(sticky=tk.NSEW)
#insert widget
w_image = default_image
try:
w_image = StockImage.get('22x22-{0}'.format(wc.classname))
except StockImageException as e:
pass
#define callback for button
def create_cb(cname):
app = AccordionFrame(root)
app.grid(sticky=tk.NSEW)
top = app.winfo_toplevel()
top.rowconfigure(0, weight=1)
top.columnconfigure(0, weight=1)
g = app.add_group('g1', 'Tk widgets')
l = tk.Label(g, text="Label1")
l.grid()
l = tk.Label(g, text="Label2")
l.grid()
g = app.add_group('g2', 'Ttk widgets')
##
app = AccordionFrame(g)
app.grid(sticky='nsew', padx="5 0")
g = app.add_group('g1', 'Containers')
l = tk.Label(g, text="Label1")
l.grid()
l = tk.Label(g, text="Label2")
l.grid()
g = app.add_group('g2', 'Control')
l = tk.Label(g, text="Label3")
l.grid()
l = tk.Label(g, text="Label4")
l.grid()
tk.mainloop()
@classmethod
def set_gimages(cls, img_open, img_close):
if cls.IMAGES is None:
cls.IMAGES = [
tk.PhotoImage(file=img_open),
tk.PhotoImage(file=img_close),]
else:
cls.IMAGES[0].configure(file=img_open)
cls.IMAGES[1].configure(file=img_close)
if __name__ == '__main__':
root = tk.Tk()
app = AccordionFrame(root)
app.grid(sticky=tk.NSEW)
top = app.winfo_toplevel()
top.rowconfigure(0, weight=1)
top.columnconfigure(0, weight=1)
g = app.add_group('g1', 'Tk widgets')
l = tk.Label(g, text="Label1")
l.grid()
l = tk.Label(g, text="Label2")
l.grid()
g = app.add_group('g2', 'Ttk widgets')
##
app = AccordionFrame(g)
app.grid(sticky='nsew', padx="5 0")
g = app.add_group('g1', 'Containers')
def __init__(self, master=None, **kw):
ttk.Frame.__init__(self, master, **kw)
self.__images = None
self.__groups = {}
self.columnconfigure(0, weight=1)
if AccordionFrame.IMAGES is None:
AccordionFrame.IMAGES = [
tk.PhotoImage(data=img_down),
tk.PhotoImage(data=img_right),]
self.__images = AccordionFrame.IMAGES