英文:
Is there a short one-line way to set the margins of a component in a Python VCL GUI App?
问题
我知道你可以像以下代码一样单独设置每个边距(上、右、下、左):
self.myPanel.AlignWithMargins = True
self.myPanel.Margins.Top = 100
self.myPanel.Margins.Right = 100
self.myPanel.Margins.Bottom = 100
self.myPanel.Margins.Left = 100
但是否有一种方法可以用一行代码设置所有四个边距,而不是为每个边距写四行代码呢?
我希望像这样使用:self.myPanel.Margins = [100, 100, 100, 100]
,但这样不起作用。我得到以下错误信息:AttributeError: Error in setting property Margins (Error: Expected a Pascal object)
。
有没有一种更短/更好的方法可以一行代码设置所有四个边距?
英文:
I know you can set each margin (Top, Right, Bottom, Left) individually like the following code:
self.myPanel.AlignWithMargins = True
self.myPanel.Margins.Top = 100
self.myPanel.Margins.Right = 100
self.myPanel.Margins.Bottom = 100
self.myPanel.Margins.Left = 100
But is there a way to set all four margins with just one line of code instead of having four lines of code (one for each margin)?
I was hoping for something like self.myPanel.Margins = [100, 100, 100, 100]
, but this doesn't work. I get the following error AttributeError: Error in setting property Margins (Error: Expected a Pascal object)
.
Is there a shorter/better way to set all four margins in one line?
答案1
得分: 0
你可以使用setBounds
函数:
self.myPanel.Margins.setBounds(100, 100, 100, 100)
英文:
You can use the setBounds
function:
self.myPanel.Margins.setBounds(100, 100, 100, 100)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论