diff --git a/test.py b/test.py index 522c6d4..f7d847b 100644 --- a/test.py +++ b/test.py @@ -62,6 +62,12 @@ def test_fontchooser_init(self): text='Abcd' * 20, title='Test') self.window.update() + def test_fontchooser_init_only_fixed(self): + FontChooser(self.window, + {'family': 'Arial', 'weight': 'bold', 'slant': 'italic'}, + text='Abcd' * 20, title='Test', only_fixed=True) + self.window.update() + def test_fontchooser_methods(self): props = {'family': "TkDefaultFont", 'weight': 'bold', 'size': 27, 'slant': 'italic'} diff --git a/tkfontchooser.py b/tkfontchooser.py index cd6a710..5704c40 100755 --- a/tkfontchooser.py +++ b/tkfontchooser.py @@ -55,7 +55,7 @@ class FontChooser(Toplevel): """Font chooser dialog.""" def __init__(self, master, font_dict={}, text="Abcd", title="Font Chooser", - **kwargs): + only_fixed=False, **kwargs): """ Create a new FontChooser instance. @@ -101,8 +101,17 @@ def __init__(self, master, font_dict={}, text="Abcd", title="Font Chooser", self.configure(bg=bg) # --- family list - self.fonts = list(set(families())) - self.fonts.append("TkDefaultFont") + if only_fixed: + all_families = list(set(families())) + self.fonts = [] + for ffamily in all_families: + fnt = Font(family=ffamily) + is_fixed = fnt.metrics('fixed') + if (is_fixed != 0): + self.fonts.append(ffamily) + else: + self.fonts = list(set(families())) + self.fonts.append("TkDefaultFont") self.fonts.sort() for i in range(len(self.fonts)): self.fonts[i] = self.fonts[i].replace(" ", "\ ")