有没有一种简洁的一行代码方式来设置Python VCL GUI应用程序中组件的边距?

huangapple go评论83阅读模式
英文:

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)

huangapple
  • 本文由 发表于 2023年7月14日 05:34:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/76683379.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定