question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to Change Font Size in Toga Label

See original GitHub issue

Describe the bug I’m building my first proper BeeWare app. My problem is fairly straightforward, but no less infuriating. I can’t seem to increase the font size within any given Label widget. This is what my app.py file looks like:

To Reproduce As per the tutorial, build a basic BeeWare app, and then amend app.py as follows:

import toga
from toga.fonts import Font, SANS_SERIF
from toga.style import Pack
from toga.style.pack import COLUMN, ROW

class Charon(toga.App):
    def startup(self):
        main_box = toga.Box(style=Pack(direction=COLUMN))

        title_label = toga.Label("Hello, world!")
        title_label.font = Font(family=SANS_SERIF, size=50)

        main_box.add(title_label)

        self.main_window = toga.MainWindow(title=self.formal_name)
        self.main_window.content = main_box
        self.main_window.show()

def main():
    result = Charon()
    return result

Then run the app using briefcase dev. (Running the app using briefcase run, or using briefcase run android - the app is intended for Android - seems to reproduce the same error.)

Expected behavior I expected setting title_label.font = Font(family=SANS_SERIF, size=50) would increase the size of the “Hello, world!” label. However, no matter what I do with the snippet size=50 - whether I set the font size to 5 or 500 - the size of the text remains unchanged. If I run the same code within an Android emulator, I run into the same issue: the font size doesn’t change.

Environment:

  • Operating System: Linux (Ubuntu 20.04.1 LTS)
  • Python version: 3.8.5
  • Software versions:
    • Briefcase: 0.3.4
    • Toga: 0.3.0

Additional context I’ve also raised this issue as a StackOverflow question.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
tomhoskercommented, Feb 2, 2021

I’ve also tried this:

title_style = Pack(direction=ROW, font_size=50, padding=50)
title_label = toga.Label("Hello, world!", style=title_style)

The padding=50 works as intended, but font_size=50 still does nothing. No exceptions are raised.

0reactions
tomhoskercommented, Feb 8, 2021

@Vipul-Cariappa Okay, I seem to have found a functional stop-gap method for fixing this bug, namely replacing my beeware-env/lib/python3.8/site-packages/toga_gtk/widgets folder with your toga_gtk/widgets folder. It would be awesome if your fix could get incorporated into the master branch. It works!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to Change Font Size in BeeWare Label - Stack Overflow
I can't seem to increase the font size within any given Label widget. This is what my app.py file looks like: import toga...
Read more >
Cannot change data label font - Microsoft Community
Hello,. you need to select all the data labels for the series. Click a data label and notice that all data labels are...
Read more >
Label — Toga 0.3.0.dev39 documentation
The Label is a text-label for annotating forms or interfaces. ... the app we also iterate over all children of this widget and...
Read more >
beeware/general - Gitter
which python file is being referenced the one in toga/widgets/Textinput or the one ... 'font-style': self.interface.style, 'font-size': self.interface.size, ...
Read more >
Changing fonts - Squarespace Help Center
This guide walks you through changing fonts on your site, including the font style, size, color, and spacing. All sites start with default ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found