
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Modify the default font in Python Tkinter
In order to change the default behavior of tkinter widgets, we generally override the option_add() method. The properties and values passed to option_add() method will reflect the changes in all the widgets in the application. Thus, changing the default font will affect the font for all the widgets defined in the application.
Example
Here we will pass two parameters into the option_add() method, i.e., option_add("*font", "font-family font-size font-style font-orientation").
#Import the required libraries from tkinter import * #Create an instance of tkinter frame win= Tk() #Set the geometry of frame win.geometry("600x400") #Change the default Font that will affect in all the widgets win.option_add( "*font", "lucida 20 bold italic" ) win.resizable(False, False) #Create a Label Label(win, text="This is a New Line").pack() Button(win, text="Button-1", width=10).pack() win.mainloop()
Output
Running the above code will set the default font as "lucida 20 bold italic" for all the widgets that uses textual information.
Now, go back to the program, remove the following line, and run it again.
win.option_add( "*font", "lucida 20 bold italic" )
The text will now appear in the default font −
- Related Questions & Answers
- Changing the Default Font for all the widgets in Tkinter
- How to modify the font size in Matplotlib-venn?
- How to modify column default value in MySQL?
- How to modify the default editor of JShell in Java 9?
- How to change the font on ttk.Entry in Tkinter?
- Default window color Tkinter and hex color codes in Tkinter
- How can we change the default font of the JTabbedPane tabs in Java?
- Tkinter Spinbox Widget Setting Default Value
- How to use a custom font in Tkinter?
- How to list available font families in Tkinter?
- How to set font for Text in Tkinter?
- Default to and select the first item in Tkinter Listbox
- How to set the font size of Entry widget in Tkinter?
- How to directly modify a specific item in a TKinter listbox?
- How do you change the default font color for all text in Matplotlib?
Advertisements