Wednesday, March 20, 2013

Set font of tkinter.Label

Set font of tkinter.Label
Set font of tkinter.Label


#tkinter for Python 3.x
#Tkinter for Python 2.x

import tkinter

def quit():
    global tkTop
    tkTop.destroy()

def setTextSize(ev=None):
    global tkLabel
    global tkScale
    tkLabel.config(font="Helvetica -%d bold" %tkScale.get())

tkTop = tkinter.Tk()
tkTop.geometry('300x200')

tkButtonQuit = tkinter.Button(tkTop, text="Quit", command=quit)
tkButtonQuit.pack()

tkLabel = tkinter.Label(text="Hello Python")
tkLabel.pack()

tkScale = tkinter.Scale(tkTop, from_=1, to=40, orient=tkinter.HORIZONTAL, command=setTextSize)
tkScale.set(18)
tkScale.pack(anchor=tkinter.CENTER)

tkinter.mainloop()