Python项目实战,,编程只有不断练习才能


编程只有不断练习才能掌握其精髓,多练练网上的习题和项目,才能掌握python的精髓。

 

参考链接:

Python 的练手项目有哪些值得推荐?  show-me-the-code

 

第 0000 题:将你的 QQ 头像(或者微博头像)右上角加上红色的数字,类似于微信未读信息数量那种提示效果。类似于图中效果

解答:需要用到PIL这个非常重要的库

from PIL import Image, ImageDraw, ImageFontdef add_num(img):    draw = ImageDraw.Draw(img)    myfont = ImageFont.truetype(‘C:/windows/fonts/Arial.ttf‘,size=20)    fillcolor = "#ff0020"    width, heigth = img.size    draw.text((width-40, 0), "lizhixin", font=myfont, fill=fillcolor)    img.save(‘result.jpg‘,‘jpeg‘)    return 0if __name__ == ‘__main__‘:    image = Image.open(‘image.jpg‘)    add_num(image)

Python项目实战

相关内容

    暂无相关文章

评论关闭