How to get the attachment values when a widget has been attached to a grid

瘦欲@ 提交于 2021-01-05 20:38:17

问题


This will show all attributes and their values of an existing widget: (I got the idea from user285594 at this post)

obj = [widget identifier]
    for pspec in obj.props:
        print(pspec.name)
        name = pspec.name.replace('-', '_')
        props = eval("button.props." + name)
        print(props)

Unfortunately, I can't find the attachment values when the widget has been attached to a grid. Does anyone know how to do this?


回答1:


The attachment and packing values are child properties, not properties, so you have to retrieve them with child_get_property().




回答2:


ptomato is right, this does the job:

    obj     = [widget identifier] 
    parent  = obj.get_parent()

    attachement = ''
    lst_props   = ['left-attach', 'top-attach', 'width', 'height']
    for prop in lst_props:
        attachement += str(parent.child_get_property(obj, prop))

    print(attachement)


来源:https://stackoverflow.com/questions/65565385/how-to-get-the-attachment-values-when-a-widget-has-been-attached-to-a-grid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!