Added Text.fonts_installed_list - returns the fonts installed as reported by tkinter.
This commit is contained in:
parent
c5fae56754
commit
81599f643b
|
@ -1,17 +1,20 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
import sys
|
|
||||||
import PySimpleGUI as sg
|
import PySimpleGUI as sg
|
||||||
from tkinter import font
|
|
||||||
import tkinter
|
|
||||||
root = tkinter.Tk()
|
|
||||||
fonts = list(font.families())
|
|
||||||
fonts.sort()
|
|
||||||
root.destroy()
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
Showing fonts in PSG / tk
|
Demo Font Previewer
|
||||||
|
|
||||||
|
Gets a list of the installed fonts according to tkinter.
|
||||||
|
Requires PySimpleGUI version 4.57.0 and newer (that's when sg.Text.fonts_installed_list was added)
|
||||||
|
|
||||||
|
Uses the Text element's class method to get the fonts reported by tkinter.
|
||||||
|
|
||||||
|
Copyright 2020, 2021, 2022 PySimpleGUI
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
fonts = sg.Text.fonts_installed_list()
|
||||||
|
|
||||||
|
|
||||||
sg.theme('Black')
|
sg.theme('Black')
|
||||||
|
|
||||||
layout = [[sg.Text('My Text Element',
|
layout = [[sg.Text('My Text Element',
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
version = __version__ = "4.56.0.8 Unreleased"
|
version = __version__ = "4.56.0.9 Unreleased"
|
||||||
|
|
||||||
_change_log = """
|
_change_log = """
|
||||||
Changelog since 4.56.0 released to PyPI on 5-Jan-2022
|
Changelog since 4.56.0 released to PyPI on 5-Jan-2022
|
||||||
|
@ -22,6 +22,8 @@ _change_log = """
|
||||||
4.56.0.8
|
4.56.0.8
|
||||||
Changed +CICKED+ to +CLICKED+ (typo) in the table header
|
Changed +CICKED+ to +CLICKED+ (typo) in the table header
|
||||||
Added constant TABLE_CLICKED_INDICATOR that is the value '+CLICKED+' so that it can be referenced instead of user's hard cording a string
|
Added constant TABLE_CLICKED_INDICATOR that is the value '+CLICKED+' so that it can be referenced instead of user's hard cording a string
|
||||||
|
4.56.0.9
|
||||||
|
Added class method Text.fonts_installed_list - returns list of fonts as reported by tkinter
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__version__ = version.split()[0] # For PEP 396 and PEP 345
|
__version__ = version.split()[0] # For PEP 396 and PEP 345
|
||||||
|
@ -3470,6 +3472,27 @@ class Text(Element):
|
||||||
return text
|
return text
|
||||||
|
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def fonts_installed_list(cls):
|
||||||
|
"""
|
||||||
|
Returns a list of strings that tkinter reports as the installed fonts
|
||||||
|
|
||||||
|
:return: List of the installed font names
|
||||||
|
:rtype: List[str]
|
||||||
|
"""
|
||||||
|
# if no windows have been created (there is no hidden master root to rely on) then temporarily make a window so the measurement can happen
|
||||||
|
if Window.hidden_master_root is None:
|
||||||
|
root = tk.Tk()
|
||||||
|
else:
|
||||||
|
root = Window.hidden_master_root
|
||||||
|
|
||||||
|
fonts = list(tkinter.font.families())
|
||||||
|
fonts.sort()
|
||||||
|
if Window.hidden_master_root is None:
|
||||||
|
root.destroy()
|
||||||
|
return fonts
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def char_width_in_pixels(cls, font, character='W'):
|
def char_width_in_pixels(cls, font, character='W'):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue