Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tkinter scaling does not work on some linux systems #87860

Closed
aunderscored mannequin opened this issue Apr 1, 2021 · 9 comments
Closed

Tkinter scaling does not work on some linux systems #87860

aunderscored mannequin opened this issue Apr 1, 2021 · 9 comments
Labels
3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes topic-tkinter type-bug An unexpected behavior, bug, or error

Comments

@aunderscored
Copy link
Mannequin

aunderscored mannequin commented Apr 1, 2021

BPO 43694
Nosy @serhiy-storchaka
Files
  • Screenshot_20210401_132045.png: Image of broken scaling
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2021-04-01.18:26:21.126>
    created_at = <Date 2021-04-01.11:33:52.343>
    labels = ['type-bug', '3.8', '3.9', 'expert-tkinter', '3.7', 'invalid']
    title = 'Tkinter scaling does not work on some linux systems'
    updated_at = <Date 2021-04-01.19:25:26.331>
    user = 'https://bugs.python.org/aunderscored'

    bugs.python.org fields:

    activity = <Date 2021-04-01.19:25:26.331>
    actor = 'aunderscored'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-04-01.18:26:21.126>
    closer = 'serhiy.storchaka'
    components = ['Tkinter']
    creation = <Date 2021-04-01.11:33:52.343>
    creator = 'aunderscored'
    dependencies = []
    files = ['49924']
    hgrepos = []
    issue_num = 43694
    keywords = []
    message_count = 9.0
    messages = ['389975', '389985', '389987', '389988', '389989', '389990', '389998', '390005', '390009']
    nosy_count = 2.0
    nosy_names = ['serhiy.storchaka', 'aunderscored']
    pr_nums = []
    priority = 'normal'
    resolution = 'not a bug'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue43694'
    versions = ['Python 3.7', 'Python 3.8', 'Python 3.9']

    @aunderscored
    Copy link
    Mannequin Author

    aunderscored mannequin commented Apr 1, 2021

    When using scaling (as in root.tk.call('scaling', somenum)), some linux systems appear to simply disregard the change.

    I recently reinstalled from Ubuntu to OpenSUSE Tumbleweed and found that scaling straight up did not work in the application I tried or the test application -- https://github.com/Athanasius/tk-scaling. (image attached)

    Tested on python 3.8.8 and 3.9.2 (pyenv)

    @aunderscored aunderscored mannequin added 3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes topic-tkinter type-bug An unexpected behavior, bug, or error labels Apr 1, 2021
    @serhiy-storchaka
    Copy link
    Member

    From "man font":

    FONT OPTIONS

       -size size
              The desired size of the font.  If the size argument is  a  posi‐
              tive  number, it is interpreted as a size in points.  If size is
              a negative number, its absolute value is interpreted as  a  size
              in pixels.  If a font cannot be displayed at the specified size,
              a nearby size will be chosen.  If size is unspecified or zero, a
              platform-dependent default size will be chosen.
    
              Sizes  should normally be specified in points so the application
              will remain the same ruler size on the screen, even when  chang‐
              ing screen resolutions or moving scripts across platforms.  How‐
              ever, specifying pixels is useful in certain circumstances  such
              as  when  a  piece of text must line up with respect to a fixed-
              size bitmap.  The mapping between points and pixels is set  when
              the  application  starts,  based  on properties of the installed
              monitor, but it can be overridden by calling the tk scaling com‐
              mand.
    

    If the font size is specified in absolute pixels the scaling factor does not affect it.

    See fix_scaling() in Lib/idlelib/run.py for example how to handle this problem.

    @aunderscored
    Copy link
    Mannequin Author

    aunderscored mannequin commented Apr 1, 2021

    I wasnt referring to fonts, I was refering to window scaling in general, which includes widgets and other things. Which are _also_ not being scaled correctly.

    The example code doesnt mess with fonts at all either, which either means the default behaves in an unexpected manner, or just that as I said scaling just straight doesnt work.

    @serhiy-storchaka
    Copy link
    Member

    What did you expect to get?

    @aunderscored
    Copy link
    Mannequin Author

    aunderscored mannequin commented Apr 1, 2021

    I'd expect the windows themselves to change size based on the percentage requested. eg as shown here https://user-images.githubusercontent.com/4589845/95577562-0a794500-0a3b-11eb-914e-9a5afc500b65.png (semirelated issue: EDCD/EDMarketConnector#750 )

    @serhiy-storchaka
    Copy link
    Member

    The size of of the window is determined by the size of its components. The size of the label and the munu is determined by the size of the font. If font has the same size and you output the same string (or string containing characters of the same proportion) you will get windows with the same size.

    @aunderscored
    Copy link
    Mannequin Author

    aunderscored mannequin commented Apr 1, 2021

    Okay that makes sense to me. But then my next question is, why does this work on some linux systems and not others without having a specified font?

    Something funky about the font size? because I'd expect the platform defaults to at least be the same on different linux systems.

    @serhiy-storchaka
    Copy link
    Member

    AFAIK X Window uses two font systems: for bitmap fonts and for scalable fonts. If default fonts on your system are bitmap fonts, they are not scaled.

    @aunderscored
    Copy link
    Mannequin Author

    aunderscored mannequin commented Apr 1, 2021

    Thanks so much for your help. To anyone in the future trying to figure this out: Apparently the default opensuse fonts (which are noto) are _not_ scalable. In my testing the following is enough to solve the issue.

    tk.font.nametofont('TkDefaultFont').configure(family='DejaVu Sans', size=10)
    

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes topic-tkinter type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant