tkinter how to change font code example
Example 1: how to change the font of a label in tkinter
from tkinter import *
window = Tk()
window.title("New Window")
window.geometry("300x250")
Label(window, text = "This is my new project in python!", font = ("Bahnschrift", 14)).pack()
Example 2: how to change font in tkinter
import tkinter.font as font
myFont = font.Font(family='Helvetica')
button = Button(parent, font=myFont)
button = Button(parent)
button['font'] = myFont
Example 3: tkinter change label text
pythonCopyimport tkinter as tk
class Test():
def __init__(self):
self.root = tk.Tk()
self.text = tk.StringVar()
self.text.set("Test")
self.label = tk.Label(self.root, textvariable=self.text)
self.button = tk.Button(self.root,
text="Click to change text below",
command=self.changeText)
self.button.pack()
self.label.pack()
self.root.mainloop()
def changeText(self):
self.text.set("Text updated")
app=Test()
Example 4: font in tkinter
import tkinter.font as TkFont
font = tkFont.Font ( option, ... )
helv36 = tkFont.Font(family="Helvetica",size=36,weight="bold")