在Tkinter图形用户界面中,我无法确定如何更改文本的颜色。我试着让Label1变成红色,Label2变成蓝色,Label3变成棕色,Label4变成黄色,但我似乎想不出来。提前谢谢:)import random

from Tkinter import * #don't import like this except for Tkinter

root = Tk() #create main window

root.title('Atarashi Sozo')

# Make and place a canvas widget for events and drawing

canvas = Canvas(root, height=600, width=600, relief=RAISED, bg='white')

canvas.grid() #Puts the canvas in the main Tk window

#Create lists

creature = ['is an Animal', 'is a Human', 'is an Artificial Intelligence',

'is an Alien', 'is a Mage','is a Reptillian','is a Shapeshifter',

'is Undead', 'is a Scorpion Hedgehog', 'is an Angel', 'is a Demon']

element = ['controls lightning', 'controls fire', 'controls nature','controls water', 'controls mater', 'controls time', 'controls gravity', 'controls life', 'controls death', 'controls wind',

'can bend any metal','controls the sun', 'controls the moon', 'controls love']

features = ['has wings', 'has markings', 'has large fangs', 'has claws', 'has a tail', 'has a weapon',

'has cybernetic parts', 'has wolf ears', 'has broken teeth', 'has a horn', 'has big ears',

'has eyes with two colors', 'has a mp3']

wildcard = ['is cursed', 'is bewitched', 'has no soul', 'killed someone', 'just learned magic',

'has no wifi', 'has unlimited memory', 'is poor', 'won the lottery', 'set the world on fire', 'visited another dimension']

colors = ['is primarily blue', 'is primarily grey', 'is primarily red', 'is primarily green', 'is primarily orange',

'is secondarily blue', 'is secondarily grey', 'is secondarily red', 'is secondarily green', 'is seconarily orange',

'is primarily black', 'is primarily purple', 'is secondarily purple', 'has all the colors of the rainbow']

handicap = ['is blind', 'is deaf', 'lost limbs', 'fears everything', 'has broken bones','has a small head','has an illness',

'has amnesia', 'is allergic to almost everything', 'is deformed']

habitat = ['lives in cyberspace', 'lives in a desert', 'lives in the mountains', 'lives in a volcano', 'lives in grasslands',

'lives on the moon', 'lives in space', 'lives on a deserted island', 'lives in a virtual world', 'lives in the underworld']

personality = ['is clingy', 'is depressed', 'is energetic', 'is angry', 'is kind', 'is a jerk', 'is goofy', 'is immature', 'is happy',

'is insane']

profession = ['is a teacher', 'is an assassin', 'is a graphic designer', 'is a programmer', 'is a photographer', 'is a blacksmith',

'is a bounty hunter', 'is an inventor', 'is a mage', 'is a monster hunter']

hobby = ['likes to cook', 'likes to draw and paint', 'likes to build things', 'likes to play games', 'likes to shop',

'studies alchemy', 'likes to write', 'likes to make music', 'likes to design', 'likes sports']

#Sets categories to choose from

categoryList = [hobby,profession,personality,habitat,handicap,colors,wildcard,features,element]

#Removes category from list if it has been choosen to remove the possibility of duplicates

catOne = random.choice(categoryList)

if catOne in categoryList: categoryList.remove(catOne)

catTwo = random.choice(categoryList)

if catTwo in categoryList: categoryList.remove(catTwo)

catThree = random.choice(categoryList)

if catThree in categoryList: categoryList.remove(catThree)

#Chooses item from category choosen

itemOne = random.choice(catOne)

itemTwo = random.choice(catTwo)

itemThree = random.choice(catThree)

#Creates the main visual almost the same as Atarashi Sozo in App Inventor

Title_box = canvas.create_rectangle(500, 90, 100, 18, outline = 'purple',width = 10, fill = 'violet')

Title_text = canvas.create_text(300, 50, text='Your Character', font=('Impact', -50))

Display_box1 = canvas.create_rectangle(600, 200, 8, 125, outline = 'blue', width = 10, fill = 'sky blue')

Label1 = canvas.create_text(300, 160, text=random.choice(creature), font=('Impact', -30,))

Display_box2 = canvas.create_rectangle(600, 300, 8, 225, outline = 'red', width = 10, fill = 'pink')

Label2 = canvas.create_text(300, 260, text=itemOne, font=('Impact', -30))

Display_box3 = canvas.create_rectangle(600, 400, 8, 325, outline = 'goldenrod', width = 10, fill = 'gold')

Label3 = canvas.create_text(300, 360, text=itemTwo, font=('Impact', -30))

Display_box4 = canvas.create_rectangle(600, 500, 8, 425, outline = 'saddle brown', width = 10, fill = 'chocolate')

Label4 = canvas.create_text(300, 460, text=itemThree, font=('Impact', -30))

#Create dummy button

class Outcomes(Frame):

def __init__(self,master):

Frame.__init__(self,master)

self.grid()

self.create_widgets()

def create_widgets(self):

self.button = Button(self, text = 'Generate Character')

self.button['command'] = self.print_text

self.button.grid()

def print_text():

print

app = Outcomes(root)

# Enter event loop. This displays the GUI and starts listening for events.

# The program ends when you close the window.

root.mainloop()

python tkinter text改变文本字体颜色_如何更改Tkinter中文本的颜色?相关推荐

  1. html表格一行设置颜色,更改表格中一行的颜色,html

    我想用html和css制作表格.但我的问题是,我希望桌子有两种颜色的行,一个橙色和一个白色....我使用JavaScript来填充表格.但我不能改变颜色在第二种情况下.什么sintax我应该使用使用J ...

  2. python上怎么改字体颜色_在python2.7中更改字体颜色

    我创造了一个帕斯卡三角形.一切都是我想要的.我现在想改变三角形中特定数字的颜色.我想要对角线的颜色不同,即:计数的数字是蓝色的,三角形的数字是橙色的.有没有一种方法可以改变不同行中数字的颜色,甚至设置 ...

  3. java 字体选择器_常见CSS3选择器和文本字体样式汇总

    常见的CSS3选择器包含:常用基本.属性.伪类.层级(组合)选择器,具体使用情况建议先阅读 常用的选择器有:标签.id.类.关联(通过父集找到子集)组合选择器,注意html页面中id是唯一的:基本选择 ...

  4. css文本字体形状_使用CSS更改文本字体

    css文本字体形状 In the last module, we discussed text formatting. By now, you already know how to work wit ...

  5. python作图设置背景颜色_如何在matplotlib中设置绘图的外部背景颜色

    敬礼 我想更改matplotlib中绘图的外部颜色.我可以找到很多很多例子,如何改变内部背景颜色,但外部背景颜色拒绝改变.在 图像的白色部分就是我所说的"外部"背景.最外面的颜色只 ...

  6. android 文本后图标_如何在Android中更改文本,图标等的大小

    android 文本后图标 Let's face it: no matter how good the screens are on our phones and tablets, the text ...

  7. 文本上划线_如何在Word中对文本进行上划线

    文本上划线 Underlining is a common task in Word, and easily done, but what if you need to overline (also ...

  8. python批量提取pdf的数据_Python批量提取PDF文件中文本的脚本

    本文实例为大家分享了Python批量提取PDF文件中文本的具体代码,供大家参考,具体内容如下 首先需要执行命令pip install pdfminer3k来安装处理PDF文件的扩展库. import ...

  9. office2010字体包_在Office 2010中使用高级字体连字

    office2010字体包 Fonts can help your documents stand out and be easier to read, and Office 2010 helps y ...

最新文章

  1. 这么流行的ZooKeeper,原来是这样设计的!
  2. Fusion360操作记录
  3. 《惠普之道》读书感-------站的角度不同,看到和思考的也就不一样
  4. spark、hive、impala、hbase、gbase在结构化数据方面查询原理对比(含parquet/orc)
  5. 褚霸 - Erlang开发实践
  6. 福利!网络工程师H3CNE认证GB0-191 考试试题库超详细解读-01。持续更新~
  7. 西门吹雪和他的剑——剑神和剑道
  8. 5个免费 UI、界面设计素材网
  9. SQL教程之使用 dbt 和 SQLfluff 整理 SQL
  10. 高数下-空间几何(一)-向量
  11. 顶尖文案app_17个文案网站 5款短视频软件,自媒体人必备,直接拿走不谢
  12. H5及微信小程序实测可用——监听手机返回键操作
  13. Java中IO流-18-flush和close方法的区别
  14. 西门菲莎大学计算机专业怎么样,西蒙菲莎大学世界排名2021年
  15. keil编译代码Program Size详解
  16. (经典Flash游戏)Zoom Keeper
  17. 「首席架构师推荐」最棒的的Flutter库,工具,教程,文章列表
  18. 第二次作业《软件工程》
  19. Vorstellungsgespraech
  20. SAP FIORI专题之一:初次接触fiori,用sap hana studio开发发布UI5程序

热门文章

  1. 这个情人节,工程师用阿里云来试着表达不一样的爱意
  2. 10行代码让你轻松搞定对象检测
  3. 八年磨一剑,阿里云ApsaraDB for HBase2.0正式上线
  4. Gartner:云安全的未来,是安全访问服务边缘架构
  5. 这个宝藏工具,会给你一种黑客般的感觉
  6. 我把这篇文章给女朋友看,她终于明白什么是「数据中台」了
  7. 架构师前辈告诉你:代码该如何才能自己写得容易,别人看得也不痛苦
  8. 11月4日,上海开源基础设施峰会,不见不散!
  9. ajax post 没有返回_Ajax异步技术之三:jQuery中的ajax学习
  10. postgre 生成数据库html文档_还在手动整理数据库文档?试试这个(螺丝钉)数据库文档生成工具...