- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Changing the Default Font for all the widgets in Tkinter
Let us consider a case where we want to change the default font of a Tkinter application. To apply the font and setting it as the default font for a particular application, we have to use option_add(**options) method where we specify a property such as background color, font, etc. The changes made after defining the method will force all the widgets to inherit the same property.
In the given script, we have set a default font for the application such that it can be used for all the widgets defined in the application.
#Import the required libraries from tkinter import * #Create an instance of Tkinter frame win = Tk() win.geometry("700x350") #Add fonts for all the widgets win.option_add("*Font", "aerial") #Set the font for the Label widget win.option_add("*Label.Font", "aerial 18 bold") # Define the backround color for all the idgets win.option_add("*Background", "bisque") #Display bunch of widgets Label(win, text="Label").pack() Button(win, text="Button").pack() #Create a Listbox widget w = Listbox(win) for i in range(5): w.insert(i, "item %d" % (i+1)) w.pack() w = Text(win, width=20, height=10) w.insert(1.0, "a text widget") w.pack() win.mainloop()
Running the above code will display a window with a Label widget, a Button, a Listbox, and a Text Widget. In the given output, all widgets inherit the same properties.
- Related Articles
- Modify the default font in Python Tkinter
- How do you change the default font color for all text in Matplotlib?
- Difference between .pack and .configure for widgets in Tkinter
- Showing and Hiding widgets in Tkinter?
- Changing the Mouse Cursor in Tkinter
- How to set padding of all widgets inside a window or frame in Tkinter?
- How to set font for Text in Tkinter?
- Changing the Default Display Value using CSS
- How to show and hide widgets in Tkinter?
- How to set the border color of certain Tkinter widgets?
- What is the difference between the widgets of tkinter and tkinter.ttk in Python?
- Configure tkinter/ttk widgets with transparent backgrounds
- How to create transparent widgets using Tkinter?
- How do you overlap widgets/frames in Python tkinter?
- How to delete Tkinter widgets from a window?