
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How to set the font size of a Tkinter Canvas text item?
Canvas is one of the flexible widgets in tkinter which controls the widgets with its power of functions, methods, and attributes. However, tkinter canvas can be used to create text using the create_text(options) constructor. We can define the text along with other properties in the constructor. After defining the text, we can control over the text style such as font-family, font-size and font-style by using font(property).
Example
Let us have a look at the following example where we will add a new text and then resize it using the font property.
#Import tkinter library from tkinter import * from tkinter import ttk #Create an instance of tkinter frame or window win= Tk() #Set the geometry of tkinter frame win.geometry("750x250") #Creating a canvas canvas= Canvas(win, width= 430, height= 450) #Create a text inside canvas text= canvas.create_text(200,40,text="Hey, Developers!", font=('Helvetica','30','bold')) canvas.pack() win.mainloop()
Output
Running the above code will display a window that contains a text in the canvas. We can resize the text in the canvas by using the font(options) attribute.
Now, change the font size from the property and run the code to see the reflected changes.
- Related Articles
- How do I find out the size of a canvas item in Tkinter?
- How to set the font size of text with JavaScript?
- How to set font for Text in Tkinter?
- How to set the font size of Entry widget in Tkinter?
- HTML5 Canvas Text Stroke for Large Font Size
- HTML5 Canvas Font Size Based on Canvas Size
- How to increase the font size of a Text widget?
- How to insert an image in a Tkinter canvas item?
- How to add text inside a Tkinter Canvas?
- How to change the font size of a text using JavaScript?
- How to change the font size of Text using FabricJS?
- How to change font-weight of a canvas-type text using Fabric.js?
- How to set the font size of Matplotlib axis Legend?
- How to increase the font size of text in Arduino IDE?
- How to set font face, style, size and color for JTextPane text in Java
