tk_fonts_02.py

# =========================================================
#
# =========================================================

import sys

# --- global variables

defaultFont = ('arial', 12)

# --- import Tkinter, ... based on which version of
# --- Python we are running

if sys.version_info.major is 3:
    from tkinter import *
    from tinker.font import *
    py3 = True
else:
    from Tkinter import *
    from tkFont import *
    py3 = False

# ---------------------------------------------------------
# main
# ---------------------------------------------------------

if __name__ == '__main__':

    # --- Tk root

    root = Tk()
    root.title('Display Fonts')

    Grid.columnconfigure(root, 0, weight=1)
    Grid.rowconfigure(root, 0, weight=1)

    # --- create a frame to hold everything

    frm = Frame(root, relief='flat', padx=4, pady=4, bg='red')
    frm.grid(row=0, column=0, sticky=N+S+E+W)

    frm.grid_columnconfigure(0, weight=1)
    frm.grid_rowconfigure(0, weight=1)

    # --- add a text area (widget) to the frame

    txt = Text(frm, relief='groove', borderwidth=2, bg='yellow',
            font=defaultFont, width=80, height=40)
    txt.grid(row=0, column=0, sticky=N+S+E+W)

    # -- insert test strings

    txt.insert(END,'a b c d\n')
    ##txt.see(END)
    txt.insert(END,'1 2 3 4 5 6 7 8 9 0\n')
    txt.insert(END,'Now is the winter of our discontent made ' +
            'glorious summer by this son of York. ' +
            'Baa baa black sheep, have you any wool?\n')

    q1 = \
'''HAMLET: To be or no to be--that is the question:
Whether 'tis nobler in the mind to suffer
The slings and arrows of outrageous fortune
Or take arms against a sea of troubles
And by opposing end them. To die, to sleep--
No more--and by a sleep to say we end
The heartache, and the thousand natural shocks
That flesh is heir to. 'Tis a consummation
Devoutly to be wished.'''

    txt.insert(END,q1)

    # --- make the text area (widget) read-only
    # --- only the script can make changes

    ##txt.bind('<Key>', lambda e: 'break')


    ##i = 0
    ##for f in sorted(Tkf.families()):
    ##    i += 1
    ##    print('Font family: {}'.format(f))

    # -- event loop

    root.mainloop()