James Ashwood
James Ashwood

Reputation: 579

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

I am trying to make a cricket scoreboard Gtk Python Application. On the scoreboard part that I would display to the players, I would like to make the score really big (bigger than putting the <big> element in). I wonder if it is possible to set size via a number.

Here is my code:

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()

By the way, this program is nowhere near being finished. I have only just started. I am just trying to get this part correct first.

Thanks!

Upvotes: 0

Views: 946

Answers (1)

MaxPlankton
MaxPlankton

Reputation: 1248

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

Text size can be set with size attributes of span tag, as shown in the pango documentation, https://developer.gnome.org/pygtk/stable/pango-markup-language.html

<span size="10000">0/0</spance> sets font size to 10000. Take note of meaning of size here.

size: The font size in thousandths of a point

Upvotes: 1

Related Questions