diff --git a/docs/app.md b/docs/app.md index f878659..c8fd32c 100644 --- a/docs/app.md +++ b/docs/app.md @@ -79,6 +79,7 @@ You can set and get the following properties: | enabled | boolean | `True` if the app is enabled | | height | int | The height of the window | | font | string | The font that widgets should use | +| fonts | tuple | A sorted tuple of the fonts available for this application | | full_screen | boolean | False | | image | image_source (string) | The file path, tkinter.PhotoImage or PIL.Image you wish to use as the window icon. | | layout | string | The layout being used by the App (`"auto"`) or (`"grid"`) | diff --git a/examples/pick_font.py b/examples/pick_font.py new file mode 100644 index 0000000..0fa74e6 --- /dev/null +++ b/examples/pick_font.py @@ -0,0 +1,17 @@ +from guizero import App, Combo, Text + +app = App("Font picker") + +Text(app, "Pick a font") + +def change_font(): + app.font = font_picker.value + +font_picker = Combo( + app, + options=app.fonts, + selected=app.font, + command=change_font + ) + +app.display() \ No newline at end of file diff --git a/guizero/App.py b/guizero/App.py index bfaa289..e552e76 100644 --- a/guizero/App.py +++ b/guizero/App.py @@ -1,4 +1,4 @@ -from tkinter import Tk, Toplevel +from tkinter import Tk, Toplevel, font from .base import BaseWindow from . import utilities as utils, system_config @@ -87,3 +87,10 @@ def destroy(self): if self == App._main_app: App._main_app = None self.tk.destroy() + + @property + def fonts(self): + """ + Returns a tuple of available fonts ('Courier', 'Public Sans', 'Roman') + """ + return sorted(font.families()) \ No newline at end of file