【问题标题】:How to change label font size in Python GUI app如何在 Python GUI 应用程序中更改标签字体大小
【发布时间】:2023-02-26 17:26:52
【问题描述】:

我正在使用 DelphiFMX GUI library for Python 并尝试更改标签组件上的字体大小,但它不起作用。

我有以下代码在我的表单上创建表单和标签:

from delphifmx import *

class HelloForm(Form):
    def __init__(self, owner):
        self.Caption = 'Hello World'
        self.Width = 1000
        self.Height = 500
        self.Position = "ScreenCenter"

        self.myLabel = Label(self)
        self.myLabel.Parent = self
        self.myLabel.Text = "Hello World!"
        self.myLabel.Align = "Client"
        self.myLabel.TextSettings.Font.Size = 50
        self.myLabel.TextSettings.HorzAlign = "Center"

我的输出形式看起来像这样:

我的“你好世界!”标签应该比它显示的大得多。

【问题讨论】:

    标签: python firemonkey


    【解决方案1】:

    啊。玩了一会儿代码后,我意识到我需要添加以下代码行以确保样式管理器没有为标签设置样式:

    self.myLabel.StyledSettings = ""
    

    如果您不清除 StyledSettings,那么它将在标签组件上使用默认样式。添加该行代码后,我的标签现在可以正常工作并正确显示:

    所以我的完整代码现在看起来像这样并且可以工作:

    from delphifmx import *
    
    class HelloForm(Form):
        def __init__(self, owner):
            self.Caption = 'Hello World'
            self.Width = 1000
            self.Height = 500
            self.Position = "ScreenCenter"
    
            self.myLabel = Label(self)
            self.myLabel.Parent = self
            self.myLabel.Text = "Hello World!"
            self.myLabel.Align = "Client"
            self.myLabel.StyledSettings = ""
            self.myLabel.TextSettings.Font.Size = 50
            self.myLabel.TextSettings.HorzAlign = "Center"
    
    def main():
        Application.Initialize()
        Application.Title = "Hello World"
        Application.MainForm = HelloForm(Application)
        Application.MainForm.Show()
        Application.Run()
        Application.MainForm.Destroy()
    
    main()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-05-11
      • 2011-09-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-04
      • 2014-08-08
      相关资源
      最近更新 更多