08/03/22 02:56:18
import yaml # PyYAML from URLリンク(pyyaml.org)
import Tkinter
import re
def build(parent, dic, commands):
widget = None
for key, val in dic.items():
o = re.match(r"(?P<name>\w+)\((?P<base>\w+)\)", key)
if o:
name, base = o.group("name", "base")
klass = getattr(Tkinter, base)
widget = klass(parent)
#widget.pack()
if parent: setattr(parent, name, widget)
if isinstance(val, dict): build(widget, val, commands)
elif key == "command":
parent["command"] = commands[val]
elif key == "pack":
parent.pack(**val) if isinstance(val, dict) else parent.pack()
elif key == "grid":
parent.grid(**val) if isinstance(val, dict) else parent.grid()
else:
parent[key] = val
return widget