如何在 Python 中将我的 Gtk Label 元素设置为特定大小?

How do I set my Gtk Label element to a certain size in Python?

我正在尝试制作板球记分牌 Gtk Python 应用程序。在我要显示给玩家的记分牌部分,我想让分数非常大(比放入 <big> 元素大)。我想知道是否可以通过数字设置大小。

这是我的代码:

from gi.repository import Gtk

Runs = 0
Wickets = 0
Batter1 = 0
Batter2 = 0
Strike = 1
Balls = 0
Overs = 0

class Window(Gtk.Window):

    def __init__(self):
        Gtk.Window.__init__(self, title="Scoreboard")
        self.set_border_width(20)
        self.set_default_size(500, 300)

        self.type = 0

        self.grid = Gtk.Grid()
        self.add(self.grid)

    def EndGame(self):
        Game = "Ended"

    def GetType(self, Type):
        if Type == "Scoreboard":
            self.type = 1
        else:
            self.type = 2

    def Show(self):
        if self.type == 1:
            Score = Gtk.Label()
            Score.set_markup("<big>" + str(Runs) + "/" + str(Wickets) + "</big>")
            self.grid.add(Score)
        else:
            pass

    def Main(self):
        pass


WinOne = Window()
WinTwo = Window()
WinOne.GetType("Scoreboard")
WinTwo.GetType("Scorer")
while(1):
    WinTwo.Main()
    WinOne.Main()
    WinOne.Show()
    WinTwo.Show()
    WinOne.show_all()
    WinTwo.show_all()
    Gtk.main()

顺便说一句,这个项目还差得远呢。我才刚刚开始。我只是想先把这部分改正。

谢谢!

def Show(self):
    if self.type == 1:
        Score = Gtk.Label()
        fontsize=10000
        Score.set_markup("<span size=\"{}\">{}/{}</span>".format(fontsize, Runs, Wickets))
        self.grid.add(Score)
    else:
        pass

可以使用 span 标签的 size 属性设置文本大小,如 pango 文档中所示,https://developer.gnome.org/pygtk/stable/pango-markup-language.html

<span size="10000">0/0</spance> 将字体大小设置为 10000。注意这里size的含义。

size: The font size in thousandths of a point