- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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).
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()
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.
- How do I find out the size of a canvas item in Tkinter?
- How to set the font size of Entry widget in Tkinter?
- How to set font for Text 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 add text inside a Tkinter Canvas?
- How to insert an image in a Tkinter canvas item?
- How to set the font size of Matplotlib axis Legend?
- How to increase the font size of text in Arduino IDE?
- Set the font size with CSS
- How can I change the text of the Tkinter Listbox item?
- How to change the size of text on a label in Tkinter?