0

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))

2 Answers2

0

If you call .config() on a widget without any parameters, it returns a dictionary containing the current configuration. So, textEntry.config() would get you a dictionary for the textEntry widget, and textEntry.config()['font'] would get you a tuple of values relating to your font settings. Assuming your font settings consist only of a size parameter (e.g. font=10)

curSize = int(textEntry.config()['font'][-1])

would get you an integer containing the current font size

asongtoruin
  • 9,794
  • 3
  • 36
  • 47
-1

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
Alex Boxall
  • 541
  • 5
  • 13