Search code examples
pythonpython-3.xtkinterfontstext-widget

Change Text Widget font in Python


I'm making a function that will increase the text widget's size by 1 every time it's called. I cannot find a way to find the current font size of the widget. I need something like:

textEntry.configure(font=(fontSize=fontSize+1))

Solution

  • This is a quick and dirty solution but it works for all fonts and can contain any valid font parameter(s).

    def increaseSize():
        font = textEntry.cget('font')       #get font information
        info = font.split(' ')              #split it into chunks
    
        #find the font size entry
        for i in info:
            if i.isdigit():
                size = int(i)
                textEntry.config(font=font.replace(i, str(size + 1)))
                break