Tkinter Text size Parameter
size is used to set the font size of the Text text area, the following example will illustrate the impact of this parameter on the font size of the text area.
Example#1
Combobox object to set the font size, font size range is 8 ~ 30, where the default size is 12. Place this object on the right of the weight object, the user can enter text in the Text text area, and then you can choose the font size, weight or font size, you can see that the text entered will have different changes due to the selected font size or weight or font size.
from tkinter import *
from tkinter.font import Font
from tkinter.ttk import *
def familyChanged(event): # font family changed
f=Font(family=familyVar.get()) # Get a new font family
text.configure(font=f) # Update font family of text
def weightChanged(event): # weight family changed
f=Font(weight=weightVar.get()) # Get new font weight
text.configure(font=f) # Update font weight of text
def sizeSelected(event): # size family changed
f=Font(size=sizeVar.get()) # Get new font size
text.configure(font=f) # Get the font size of the text
root = Tk()
root.title("apidemos.com")
root.geometry("300x180")
# create toolbar
toolbar = Frame(root,relief=RAISED,borderwidth=1)
toolbar.pack(side=TOP,fill=X,padx=2,pady=1)
# create font family OptionMenu
familyVar = StringVar()
familyFamily = ("Arial","Times","Courier")
familyVar.set(familyFamily[0])
family = OptionMenu(toolbar,familyVar,*familyFamily,command=familyChanged)
family.pack(side=LEFT,pady=2)
# create font weight OptionMenu
weightVar = StringVar()
weightFamily = ("normal","bold")
weightVar.set(weightFamily[0])
weight = OptionMenu(toolbar,weightVar,*weightFamily,command=weightChanged)
weight.pack(pady=3,side=LEFT)
# create font size Combobox
sizeVar = IntVar()
size = Combobox(toolbar,textvariable=sizeVar)
sizeFamily = [x for x in range(8,31)]
size["value"] = sizeFamily
size.current(4)
size.bind("<<ComboboxSelected>>",sizeSelected)
size.pack(side=LEFT)
# create Text
text = Text(root)
text.pack(fill=BOTH,expand=True,padx=3,pady=2)
text.focus_set()
root.mainloop()
Output: