python学习笔记之tkinter中的label
2016-11-29 21:12
513 查看
from tkinter import * longtext='''多行 文本''' master = Tk() master.title("label学习") w0=Label(master,text=longtext) w0.pack() photo=PhotoImage(file="b.png") w=Label(master,image=photo) w.pack() mainloop()
#!/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学习笔记 menu控件 02
- python学习笔记_Tkinter
- Python:GUI之tkinter学习笔记2界面布局显示
- python Tkinter的学习笔记
- Python 【Tkinter 常用控件】 学习笔记
- python学习笔记——Tkinter GUI编程——简介
- Python学习笔记--Tkinter制作GUI
- 鱼c笔记——Python的GUI编程(二):Tkinter的两大常用组件Label和Button
- Python Tkinter 学习笔记(二)Hello_again
- python tkinter学习 之Label,Button,Listbox
- python tkinter 学习笔记(1)
- Python学习笔记_02:使用Tkinter连接MySQL数据库实现登陆注册功能
- Python tkinter学习2 label与button
- Python Tkinter 学习笔记(一) Hello world
- python Tkinter学习笔记 简单的计算器 03
- Tkinter学习笔记之Label标签&Button按钮
- Python:GUI之tkinter学习笔记之messagebox、filedialog
- Python学习笔记 GUI-Tkinter
- python学习笔记——Tkinter GUI编程——简介
- Python:GUI之tkinter学习笔记3事件绑定