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

在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()

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/527430.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

qt 在label上以光标位置进行缩放_缩放|位移|渐变简单动画

本文简单介绍Qt的一些动画效果(缩放,位移,渐变)。缩放动画将窗口的geometry(位置,大小)属性作为动画参考实现缩放动画。代码QWidget *w new QWidget;w->setWindowTitle(QStringLiteral("缩放动画Qt君"));w->resize(320, 240)…

虚拟机中ubuntu可以使用显卡吗_在KVM下使用ubuntu19.10安装Anbox

导言:Anbox是一个Android模拟器,可以从linux系统运行Android应用程序或游戏。对于Anbox的安装已经有了各种教程,主要针对ubuntu18.04之前的版本。最近在做一个关于虚拟机中跑安卓的项目,因此在虚拟机中使用ubuntu18.04系统&#x…

mysql tree_MySQL树形遍历(二)

转载自:http://blog.csdn.net/dreamer0924/article/details/7580278英文原文:http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/预排序遍历树算法:modified preorder tree traversal algorithm这个算法有如下几个数据结构1 lft 代表左 left2 r…

python导入pillow模块_Python:argparse模块和pillow-image

刚入门学python,最近照着实验楼做了一个基础的练手项目:图像转字符画,里面用到了argparse和pillow-image。看了python关于这个函数的介绍和网上的一些教程,想把重点整理出来,正好最近发现前一天还挺明白的内容&#xf…

mysql 常用数据库连接池_常见的数据库连接池

欢迎进入Java社区论坛,与200万技术人员互动交流 >>进入 2.C3P0 在Hibernate和Spring中默认支持该数据库连接池 需要引入:c3p0-0.9.1.2.jar包,如果报错再引入mchange-commons-0.2.jar 1. 在类路径下编写一个c3p0-config.xml文件 c3p0-co…

win32_bios 的对象编辑器无法保存对象_怎样创建Femap对象

创建Femap对象主要有两种方式,一是直接在Femap内置的API程序窗体中创建,二是在API程序窗口以外的开发环境中创建。一、使用FEMAP集成的API程序窗口开始使用FEMAP API的最快方法是打开API编程窗口。它提供了一个完整的编辑、调试和运行的环境,…

nginx 在阿里云怎么安装mysql_阿里云Linux服务器安装 nginx+mysql+php

阿里云Linux服务器安装 nginxmysqlphp步骤1、登录服务器2、下载安装包3、将安装包上传到服务器的/home目录下注:使用rz sz命令进行本地和服务器间的上传、下载,安装命令yum install -y lrzsz4、解压安装包注:使用yum install unzip -y安装解压工具,安装完…

未定义变量: data_三、变量声明

三、变量声明var声明主要特点: - var是函数作用域,只针对函数声明 - 可以多次声明同一个变量不会报错 - 捕获变量怪异之处function fnVar(flag: boolean) {if(flag) {var x 10;}return x; } fnVar(true); // 10 fnVar(false); // undefinedvar isDone: …

阿帕奇链接mysql_apache guacamole 使用mysql 连接

1.创建一个临时文件夹,用来存放mysql-java连接器mkdir tempauth2.下载相关文件cd tempauthwget https://jaist.dl.sourceforge.net/project/guacamole/current/extensions/guacamole-auth-jdbc-0.9.14.tar.gzwget https://cdn.mysql.com//Downloads/Connector-J/mys…

表单的默认提交方式_对于PHP表单提交有哪集中方式讲解

PHP 做网页后端还是很优秀的&#xff0c;PHP 表单提交&#xff0c;不外乎两种方法&#xff0c;即 GET 和 POST 方法&#xff1b;PHP后台使用全局变量$_POST;$_GET;来获取提交数据。代码&#xff1a;<!DOCTYPE HTML> <html> <head><meta charset"utf-…

spring中怎么让事物提交_Spring怎么在一个事务中开启另一个事务

点击上方“Java知音”&#xff0c;选择“置顶公众号”技术文章第一时间送达&#xff01;作者&#xff1a;Mazinmy.oschina.net/u/3441184/blog/893628Spring项目&#xff0c;需要在一个事务中开启另一个事务。上面提到的情景可能不常见&#xff0c;但是还是会有的&#xff0c;一…

通过对象指针的方式强行指定到子类_C++中的虚指针与虚函数表

​ 最近在逛B站的时候发现有候捷老师的课程&#xff0c;如获至宝。因此&#xff0c;跟随他的讲解又复习了一遍关于C的内容&#xff0c;收获也非常的大&#xff0c;对于某些模糊的概念及遗忘的内容又有了更深的认识。以下内容是关于虚函数表、虚函数指针&#xff0c;而C中的动态…

datax oracle mysql_从 MySQL 到 Lindorm时序引擎 的数据迁移

背景本文主要介绍如何使用阿里巴巴的开源工具Datax 实现从 MySQL 到 时序引擎 的数据迁移。DataX相关使用介绍请参阅 DataX 的下面将首先介绍 DataX 工具本身&#xff0c;以及本次迁移工作涉及到的两个插件(MySQL Reader 和 TSDB Writer)。DataXDataX 是阿里巴巴集团内被广泛使…

如何手动输入给数组赋值_你是否真的了解VBA数组呢?让我带你认识一下真正的数组...

大家好&#xff0c;我们今日继续讲解VBA代码解决方案的第110讲内容&#xff1a;VBA数组讲解&#xff0c;什么是数组&#xff0c;如何定义数组&#xff0c;如何创建数组一、什么是数组 就是数组共享一个名字&#xff0c;有着多个元素按顺序排列的变量。在数组中&#xff0c;元素…

redhat9安装mysql_redhat 9.0 安装mysql

在官网上下载了MySQL-5.5.9-1.rhel5.i386.tar包 &#xff0c;将文件以二进制的形式ftp到虚拟机rehat上解压文件到MySQY-5文件夹下&#xff1a;然后将路径切换到解压目录下运行 rpm -ivh *.rpm --force报如下错&#xff1a;rootlocalhost MySQL-5]# rpm -ivh *.rpm --forceerror…

为什么整数在python中表示d_python中整数的缓存机制

在python中&#xff0c;如下代码结果一定不会让你吃惊&#xff1a;Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:06:53) [MSC v.1600 64 bit (AMD64)] on win32Type "copyright", "credits" or "license()" for more information.>&g…

MySQL中序列的作用_MySql中序列的应用和总结

Mysql中的序列主要用于主键&#xff0c;主键是递增的字段&#xff0c;不可重复。Mysql与Oracle不同的是&#xff0c;它不支持原生态的sequence&#xff0c;需要用表和函数的组合来实现类似序列的功能。1.首先创建序列的主表/*Navicat Premium Data TransferSource Server : MyS…

python内置模块重要程度排名_python常用内置模块

#持续更新#在使用内置模块的时候需要导入&#xff0c;例如import abc&#xff0c;则导入abc模块&#xff0c;当然模块也可以自己写&#xff0c;相当于一个类&#xff0c;后面放到类里说&#xff0c;这个因为环境闲置&#xff0c;有些无法执行&#xff0c;只能理解了#os系统操作…

路由器装上去没有网络_5G网络那么快,今后路由器没有存在的价值了?

从一些宣传来看&#xff0c;即将商用的5G网速确实很快&#xff0c;号称10Gbps&#xff0c;比有线宽带还要快。既然5G网速那么快了&#xff0c;还有必要装宽带和路由器吗?先来纠正一个误区&#xff0c;5G网络的理论速度与实际速度是有很大差别的!!目前很多宣传中所说的5G网速最…

python爬取新闻网站内容findall函数爬取_Python爬取新闻网标题、日期、点击量

最近接触Python爬虫&#xff0c;以爬取学校新闻网新闻标题、日期、点击量为例&#xff0c;记录一下工作进度目前&#xff0c;感觉Python爬虫的过程无非两步&#xff1a;Step1.获取网页url(利用Python库函数import urllib2)Step2.利用正则表达式对html中的字符串进行匹配、查找等…