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

问题描述 投票:0回答:1

我正在尝试制作板球记分牌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()

顺便说一下,这个程序还差得远。我才刚刚开始。我只是想首先使这一部分正确。

谢谢!

python gtk gtk3
1个回答
1
投票
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

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

© www.soinside.com 2019 - 2024. All rights reserved.