原文链接:http://www.limerence2017.com/2017/12/28/python19/#more
介绍几个python中常见的第三方库.
Pillow
Pillow简称PIL,是python中常用的图形图像处理模块。写一个简单的例子
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
from PIL import Image, ImageFilter
|
Image.open函数打开一张图片,然后调用thumbnail进行缩放,调用save进行存储。filter函数
为滤镜函数,可以匹配不同的滤镜模式,如模糊,边界效果等等。
原图:

通过滤镜模糊模式:

通过滤镜边界模式:

下面利用PIL库实现一个生成验证码的小程序
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
from PIL import Image, ImageDraw, ImageFont, ImageFilter import random
|
chardet检测编码
1 2 3 4 5 6 7 8 9 10 11
|
import chardet rs = chardet.detect(b'Hello, world!') print(rs)
data = '江船火独明'.encode('gb2312') rs = chardet.detect(data) print(rs)
data2 = '此情可待成追忆'.encode('utf-8') rs2 = chardet.detect(data2) print(rs2)
|
用chardet可以判断编码方式,在不知道字节是按照什么格式编码时可以采用chardet。
tkinter 制作GUI界面
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
from tkinter import *
class Application(Frame): def __init__(self, master = None): Frame.__init__(self,master) self.pack() self.createWidgets()
def createWidgets(self): self.helloLabel = Label(self, text='Hello, world!') self.helloLabel.pack() self.quitButton = Button(self, text = 'Quit', command=self.quit) self.quitButton.pack()
app = Application()
|
pack()方法是将Widgets对象加载到父容器中。
具体的API读者可以查看手册。这些第三方库用到的时候再具体学习即可。
我的公众号,谢谢关注:
