PySimpleGUI中如何将动态生成的按钮右对齐?
PySimpleGUI动态生成按钮右对齐的实现方法
有两种简单的方法可以实现动态生成按钮的右对齐:
方法一:使用sg.push()占位
sg.push()会自动填充左侧空白空间,将按钮挤到窗口右侧,直接在动态按钮列表前添加即可:
words = "S-C-I-E-N-C-E".split('-') layout = [ [sg.push()] + [sg.Button(word, size=2) for word in words] ]
方法二:利用sg.Column的右对齐属性
把动态生成的按钮嵌套在sg.Column组件中,通过设置justification='right'让Column内部元素右对齐:
words = "S-C-I-E-N-C-E".split('-') layout = [ [sg.Column([[sg.Button(word, size=2) for word in words]], justification='right')] ]
内容的提问来源于stack exchange,提问作者PyiPath2022
相关产品推荐
相关产品推荐

