python Tkinter(2)label 包含图像显示
来源:互联网 发布:公务员网络培训课程 编辑:程序博客网 时间:2024/06/02 00:33
上一篇http://blog.csdn.net/u011437680/article/details/40016649
大致说了怎么建一个图形化界面,现在细致了解一个每个控件的功能
x
#!/usr/bin/python
#coding=utf-8
from Tkinter import *
#导入tk模块
top = Tk()
#初始化Tk
top.title('label test')
#标题显示为label test
label = Label(top, text = 'this is my first label')
#创建一个label,它属于top窗口,文本显示内容为.....
label.pack()
top.mainloop()
#进入消息循环
来一个可以显示图片的,PhotoImage似乎读不了.jpg i格式的
#!/usr/bin/python
#coding=utf-8
from Tkinter import *
#导入tk模块
top = Tk()
#初始化Tk
top.title('label test')
#标题显示为label test
label = Label(top, text = 'this is my first label')
#创建一个label,它属于top窗口,文本显示内容为.....
label.pack()
bm = PhotoImage(file = '/home/fangxu/图片/4.png')
label2 = Label(top, image = bm)
label2.bm = bm
label2.pack()
top.mainloop()
#进入消息循环
然后来一个可以更新图片的
#coding=utf-8
from Tkinter import *
def change():
label.configure(image = bm2)
top = Tk()
bm = PhotoImage(file = "/home/fangxu/图片/4.png")
bm2 = PhotoImage(file = "/home/fangxu/图片/5.png")
label = Label(top, image = bm)
label.pack()
button = Button(top, text = "changepicture", command = change)
button.pack()
top.mainloop()
上图
按下changepicture 显示另一张图片
前景色和背景色
fg bg
有六种颜色可以使用
Red
Green
Blue
Yellow
LightBlue
置宽度与高度
width: 宽度
height: 高度
一个程序演示这两个
from Tkinter import *
top = Tk()
label1 = Label(top, fg = 'blue', bg = 'red',width = 30, height = 12, text = "color")
label1.pack()
top.mainloop()
截图这个就不截了,比较简单~
图片和文字并存
compound: 指定文本(text)与图像(bitmap/image)是如何在Label上显示,缺省为None,
当指定image/bitmap时,文本(text)将被覆盖,只显示图像了。可以使用的值:
left: 图像居左
right: 图像居右
top: 图像居上
bottom:图像居下
center:文字覆盖在图像上
#图像居下
Label(root,text = '图在下',compound = 'bottom',bitmap = '....').pack()
#图像居上
Label(root,text = '图在上',compound = 'top',bitmap = '....').pack()
#图像居右
Label(root,text = '图在右',compound = 'right',bitmap = '...').pack()
#图像居左
Label(root,text = '图在左',compound = 'left',bitmap = '.....').pack()
#文字覆盖在图像上
Label(root,text = '我在中间',compound = 'center',bitmap = '......').pack()
在图片上尝试以下文字覆盖在图片上的,改动一下上边的程序
- python Tkinter(2)label 包含图像显示
- Python tkinter label 更新
- Python 图形界面Tkinter Label 详解
- python图像化Tkinter
- Tkinter Label 文本的多行显示
- python tkinter label编写案例分析
- python学习笔记之tkinter中的label
- Python tkinter 用例 含button label Entry
- QT Label显示图像
- Tkinter:Label
- Python图像处理(2):图像显示
- Python Imaging Library: ImageTk Module(图像Tkinter模块)
- 小白学tkinter(Label(标签)组件)
- Python tkinter学习2
- Python GUI (Tkinter)
- python Tkinter (1)
- Tkinter(python-GUI)
- 【图像语义分割】Label data的标注--Labelme(python)
- 揭秘各种互联网骗局,让你闯江湖不挨刀
- Android EventBus学习总结
- P2P网络借贷系统简要解读
- 积累(五-大数据处理)
- 用php 把数组中偶数,选择出来
- python Tkinter(2)label 包含图像显示
- [自己记录]文件名按数字顺序输入文件
- hints: select /*+index()*/
- codeigniter 不能引入css样式表
- Python正则表达式指南
- JSON和JSONP,跨区 AJAX获取值
- Find Metal Mineral - HDU 4003 dp
- java使用Apache POI操作excel文件
- unity3d报错:Internal compiler error. See the console log for more information. output was: ......