文档介绍:这系列教程完全以代码的形式来写的,目标是:读者看代码和注释就可以理解代码的意
思。但这里的读者需要具备的几项技能:
熟悉python语言的基础,如果还没有,先看一下python的教程吧,英文官方();
对界面编程有一定的了解,知道基本rorinbitmapdata
'''
虽然二者均没有起作用,还是要说明一下,bitmap与image的关系,如果同时指定这两参
数,image
优先。
'''
'''
fg:前景色
bg:背景色
设置背景色的一个大的用处是:可以判断控件的大小(不同的控件使用不同的颜色,后续
内容
可以使用此特性来调试container)
III
fromTkinterimport*
root=Tk()
在创建Label时指定各自使用的颜色
'''可以使用的颜色值:'''
使用颜色名称
Label(root,fg='red',bg='blue',text='HelloIamTkinter').pack()
使用颜色值#RRGGBB
Label(root,fg='red',bg='#FF00FF,text='HelloIamTkinter').pack()
#使用系统相关的颜色值(Windows),不建议使用这样的值,不利于平台移植
Label(root,fg='red',bg='SystemButtonShadow',text='HelloIamTkinter').pack()()'''
.使用颜色名称
Red
Green
Blue
Yellow
LightBlue
.使用#RRGGBB
label=Label(root,fg='red',bg='#FF00FF',text='HelloIamTkinter')指定背景色为绯红色
.除此之外,Tk还支持与OS相关的颜色值,如Windows支持
SystemActiveBorder,
SystemActiveCaption,
SystemAppWorkspace,
SystemBackground,
'''
'''
width:宽度
height:高度
'''
fromTkinterimport*
root=Tk()
创建三个Label,分别显示red,blue,yellow
注意三个Label的大小,它们均与文本的长度有关
Label(root,text='red',bg='red').pack()
Label(root,text='blue',bg='blue').pack()
Label(root,text='yellow',bg='yellow').pack()
#再创建三个Label,与上次不同的是这三个Label均使用width和heigth属性
三个Label的大小由width和height指定
Label(root,bg='red',width=10,height=3).pack()
Label(root,bg='blue',width=10,height=3).pack()
Label(root,bg='yellow',width=10,height=3).pack()
()
'''
compound:指定文本(text)与图像(bitmap/image)是如何在Label上显示,缺省为None,
当指定image/bitmap时,文本(text)将被覆盖,只显示图像了。可以使用的值:
left:图像居左
right:图像居右
top:图像居上
bottom:图像居下
center:文字覆盖在图像上
bitmap/image:
显示在Label上的图像text:
显示在Label上的文本
label=Label(root,text='Error',compound='left',bitmap='error')IIIfromTkinterimport*
root=Tk()
演示compound的使用方法
图像与文本在Label中的位置
图像居下
Label(root,text='botton'compound='bottom',bitmap='error').pack()
图像居上
Label(root,text='top'compound='top',bitmap='error').pack()
图像居右
right '.compound = ' right ',bitmap = ' error ').pack()
left '.compound = ' left '.bitmap = ' error ').pack()
La