简体   繁体   中英

How to change the font of text in tkinter Python

I want to change the text font in tkinter. How am I supposed to do that? I am new to tkinter and I don't understand. Also, I have inserted a text, is its syntax correct?

self.text = tk.Text(parent)
self.text.insert(tk.END, "Welcome to Emotion Detector!")
self.text.pack()

I have only imported tkinter as tk. nothing else. Am I supposed to import anything else?

For setting the font, font size and type you can use the the tuple:

self.text.configure(font = ("Arial", 20, "bold"))

Syntax for text insertion is ok, but there are neater ways of doing this, depending on what you are trying to achieve, fe using labels (which have method.config):

self.label = Label(parent, text = "Some text")
self.label.config(font = ("Courier New", 14))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM