简体   繁体   English

如何更改 python 中文本的颜色?

[英]how can I change the colour of my text in python?

i'm making a witcher themed combat game for a school project, and I cannot figure out how to change the colour of my text.我正在为一个学校项目制作一个巫师主题的战斗游戏,但我不知道如何更改文本的颜色。

my code so far:到目前为止我的代码:

from tkinter import *
import random

root = Tk()

background = PhotoImage(file = 'background.png')
win_screen_image = PhotoImage(file = 'win_screen.png')
lose_screen_image = PhotoImage(file = 'lose_screen.png')


def introductionCanvas():
    intro_screen = Canvas(root, height = 720, width = 1280)
    intro_screen.create_image(0, 0, image = background, anchor = 'nw')
    intro_screen.pack()
    intro_text = intro_screen.create_text(240, 80, font = 'Calibri 18', text = '     Welcome, Witcher\nPlease Enter Your Name:', )

introductionCanvas()
root.mainloop()

I tried to use tag_configure, but then I had to change the.create_text to a intro_screen = Text(root, ...), and I couldn't figure out how to add the actual text without getting an error.我尝试使用 tag_configure,但后来我不得不将 the.create_text 更改为 intro_screen = Text(root, ...),而且我不知道如何在不出错的情况下添加实际文本。

You can just add fill = 'red' or what ever color to change it in the same place you change font:您可以在更改字体的同一位置添加fill = 'red'或任何颜色来更改它:

intro_text = intro_screen.create_text(240, 80, font = 'Calibri 18', fill = 'red', text = '     Welcome, Witcher\nPlease Enter Your Name:', )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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