Python 打印自己设计的字体的实例讲解


Posted in Python onJanuary 04, 2021

通过对 26 个字母的设定,设置自己要输出的字体。

name = "RUNOOB"
 
# 接收用户输入
# name = input("输入你的名字: \n\n") 
 
lngth = len(name) 
l = "" 
 
for x in range(0, lngth): 
  c = name[x] 
  c = c.upper() 
   
  if (c == "A"): 
    print("..######..\n..#....#..\n..######..", end = " ") 
    print("\n..#....#..\n..#....#..\n\n") 
     
  elif (c == "B"): 
    print("..######..\n..#....#..\n..#####...", end = " ") 
    print("\n..#....#..\n..######..\n\n") 
     
  elif (c == "C"): 
    print("..######..\n..#.......\n..#.......", end = " ") 
    print("\n..#.......\n..######..\n\n") 
     
  elif (c == "D"): 
    print("..#####...\n..#....#..\n..#....#..", end = " ") 
    print("\n..#....#..\n..#####...\n\n") 
     
  elif (c == "E"): 
    print("..######..\n..#.......\n..#####...", end = " ") 
    print("\n..#.......\n..######..\n\n") 
     
  elif (c == "F"): 
    print("..######..\n..#.......\n..#####...", end = " ") 
    print("\n..#.......\n..#.......\n\n") 
     
  elif (c == "G"): 
    print("..######..\n..#.......\n..#.####..", end = " ") 
    print("\n..#....#..\n..#####...\n\n") 
     
  elif (c == "H"): 
    print("..#....#..\n..#....#..\n..######..", end = " ") 
    print("\n..#....#..\n..#....#..\n\n") 
     
  elif (c == "I"): 
    print("..######..\n....##....\n....##....", end = " ") 
    print("\n....##....\n..######..\n\n") 
     
  elif (c == "J"): 
    print("..######..\n....##....\n....##....", end = " ") 
    print("\n..#.##....\n..####....\n\n") 
     
  elif (c == "K"): 
    print("..#...#...\n..#..#....\n..##......", end = " ") 
    print("\n..#..#....\n..#...#...\n\n") 
     
  elif (c == "L"): 
    print("..#.......\n..#.......\n..#.......", end = " ") 
    print("\n..#.......\n..######..\n\n") 
     
  elif (c == "M"): 
    print("..#....#..\n..##..##..\n..#.##.#..", end = " ") 
    print("\n..#....#..\n..#....#..\n\n") 
     
  elif (c == "N"): 
    print("..#....#..\n..##...#..\n..#.#..#..", end = " ") 
    print("\n..#..#.#..\n..#...##..\n\n") 
     
  elif (c == "O"): 
    print("..######..\n..#....#..\n..#....#..", end = " ") 
    print("\n..#....#..\n..######..\n\n") 
     
  elif (c == "P"): 
    print("..######..\n..#....#..\n..######..", end = " ") 
    print("\n..#.......\n..#.......\n\n") 
     
  elif (c == "Q"): 
    print("..######..\n..#....#..\n..#.#..#..", end = " ") 
    print("\n..#..#.#..\n..######..\n\n") 
     
  elif (c == "R"): 
    print("..######..\n..#....#..\n..#.##...", end = " ") 
    print("\n..#...#...\n..#....#..\n\n") 
     
  elif (c == "S"): 
    print("..######..\n..#.......\n..######..", end = " ") 
    print("\n.......#..\n..######..\n\n") 
     
  elif (c == "T"): 
    print("..######..\n....##....\n....##....", end = " ") 
    print("\n....##....\n....##....\n\n") 
     
  elif (c == "U"): 
    print("..#....#..\n..#....#..\n..#....#..", end = " ") 
    print("\n..#....#..\n..######..\n\n") 
     
  elif (c == "V"): 
    print("..#....#..\n..#....#..\n..#....#..", end = " ") 
    print("\n...#..#...\n....##....\n\n") 
     
  elif (c == "W"): 
    print("..#....#..\n..#....#..\n..#.##.#..", end = " ") 
    print("\n..##..##..\n..#....#..\n\n") 
     
  elif (c == "X"): 
    print("..#....#..\n...#..#...\n....##....", end = " ") 
    print("\n...#..#...\n..#....#..\n\n") 
     
  elif (c == "Y"): 
    print("..#....#..\n...#..#...\n....##....", end = " ") 
    print("\n....##....\n....##....\n\n") 
     
  elif (c == "Z"): 
    print("..######..\n......#...\n.....#....", end = " ") 
    print("\n....#.....\n..######..\n\n") 
     
  elif (c == " "): 
    print("..........\n..........\n..........", end = " ") 
    print("\n..........\n\n") 
     
  elif (c == "."): 
    print("----..----\n\n")

执行以上代码输出结果为:

..######..
..#....#..
..#.##...
..#...#...
..#....#..

..#....#..
..#....#..
..#....#..
..#....#..
..######..

..#....#..
..##...#..
..#.#..#..
..#..#.#..
..#...##..

..######..
..#....#..
..#....#..
..#....#..
..######..

..######..
..#....#..
..#....#..
..#....#..
..######..

..######..
..#....#..
..#####...
..#....#..
..######..

实例扩展

Python打印彩色字体的方法

#################################################################
import ctypes
STD_INPUT_HANDLE = -10
STD_OUTPUT_HANDLE = -11
STD_ERROR_HANDLE = -12
FOREGROUND_BLACK = 0x0
FOREGROUND_BLUE = 0x01 # text color contains blue.
FOREGROUND_GREEN = 0x02 # text color contains green.
FOREGROUND_RED = 0x04 # text color contains red.
FOREGROUND_INTENSITY = 0x08 # text color is intensified.
BACKGROUND_BLUE = 0x10 # background color contains blue.
BACKGROUND_GREEN = 0x20 # background color contains green.
BACKGROUND_RED = 0x40 # background color contains red.
BACKGROUND_INTENSITY = 0x80 # background color is intensified.
class Color:
''''''' See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winprog/winprog/windows_api_reference.asp
for information on Windows APIs.'''
std_out_handle = ctypes.windll.kernel32.GetStdHandle(STD_OUTPUT_HANDLE)
def set_cmd_color(self, color, handle=std_out_handle):
"""(color) -> bit
Example: set_cmd_color(FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY)
"""
bool = ctypes.windll.kernel32.SetConsoleTextAttribute(handle, color)
return bool
def reset_color(self):
self.set_cmd_color(FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE)
def print_red_text(self, print_text):
self.set_cmd_color(FOREGROUND_RED | FOREGROUND_INTENSITY)
print print_text
self.reset_color()
def print_green_text(self, print_text):
self.set_cmd_color(FOREGROUND_GREEN | FOREGROUND_INTENSITY)
print print_text
self.reset_color()
def print_blue_text(self, print_text):
self.set_cmd_color(FOREGROUND_BLUE | FOREGROUND_INTENSITY)
print print_text
self.reset_color()
def print_red_text_with_blue_bg(self, print_text):
self.set_cmd_color(FOREGROUND_RED | FOREGROUND_INTENSITY | BACKGROUND_BLUE | BACKGROUND_INTENSITY)
print print_text
self.reset_color()
clr = Color()
# clr.print_red_text('red')
# clr.print_green_text('green')
# clr.print_blue_text('blue')
# clr.print_red_text_with_blue_bg('background')
###########################################################

到此这篇关于Python 打印自己设计的字体的实例讲解的文章就介绍到这了,更多相关Python 打印自己设计的字体内容请搜索三水点靠木以前的文章或继续浏览下面的相关文章希望大家以后多多支持三水点靠木!

Python 相关文章推荐
python轻松实现代码编码格式转换
Mar 26 Python
Python实现压缩与解压gzip大文件的方法
Sep 18 Python
python使用matplotlib绘制柱状图教程
Feb 08 Python
Python实现判断字符串中包含某个字符的判断函数示例
Jan 08 Python
python中计算一个列表中连续相同的元素个数方法
Jun 29 Python
numpy中loadtxt 的用法详解
Aug 03 Python
python面向对象入门教程之从代码复用开始(一)
Dec 11 Python
python3 线性回归验证方法
Jul 09 Python
python中tkinter的应用:修改字体的实例讲解
Jul 17 Python
Python 画出来六维图
Jul 26 Python
python 实现读取csv数据,分类求和 再写进 csv
May 18 Python
python使用torch随机初始化参数
Mar 22 Python
Python关于拓扑排序知识点讲解
Jan 04 #Python
Python经典五人分鱼实例讲解
Jan 04 #Python
Python约瑟夫生者死者小游戏实例讲解
Jan 04 #Python
python邮件中附加文字、html、图片、附件实现方法
Jan 04 #Python
python自动化发送邮件实例讲解
Jan 04 #Python
Python Selenium库的基本使用教程
Jan 04 #Python
selenium学习教程之定位以及切换frame(iframe)
Jan 04 #Python
You might like
谈谈PHP语法(4)
2006/10/09 PHP
php magic_quotes_gpc的一点认识与分析
2008/08/18 PHP
PHP实现删除多重数组对象属性并重新赋值的方法
2017/06/07 PHP
php中字符串和整数比较的操作方法
2019/06/06 PHP
php并发加锁问题分析与设计代码实例讲解
2021/02/26 PHP
return false,对阻止事件默认动作的一些测试代码
2010/11/17 Javascript
Javascript 面向对象编程(一) 封装
2011/08/28 Javascript
javascript对select标签的控制(option选项/select)
2013/01/31 Javascript
Javascript模块化编程详解
2014/12/01 Javascript
node.js下when.js 的异步编程实践
2014/12/03 Javascript
JQuery页面地址处理插件jqURL详解
2015/05/03 Javascript
jquery中trigger()无法触发hover事件的解决方法
2015/05/07 Javascript
快速掌握Node.js模块封装及使用
2016/03/21 Javascript
JQuery解析XML的方法小结
2016/04/02 Javascript
jQuery Validate插件实现表单验证
2016/08/19 Javascript
深入浅出ES6之let和const命令
2016/08/25 Javascript
15个非常实用的JavaScript代码片段
2016/12/18 Javascript
nodejs进阶(6)—连接MySQL数据库示例
2017/01/07 NodeJs
深入理解Vue router的部分高级用法
2018/08/15 Javascript
JavaScript的Proxy可以做哪些有意思的事儿
2019/06/15 Javascript
微信小程序wx.request的简单封装
2019/11/13 Javascript
浅谈javascript如何获取文件后缀名
2020/08/07 Javascript
快速解决Vue、element-ui的resetFields()方法重置表单无效的问题
2020/08/12 Javascript
JS实现页面鼠标点击出现图片特效
2020/08/19 Javascript
python使用socket远程连接错误处理方法
2015/04/29 Python
python 两种方法修改文件的创建时间、修改时间、访问时间
2020/09/26 Python
css3 旋转按钮 使用CSS3创建一个旋转可变色按钮
2012/12/31 HTML / CSS
美国排名第一的在线葡萄酒商店:Wine.com
2016/09/07 全球购物
印度尼西亚综合购物网站:Lazada印尼
2016/09/07 全球购物
英国派对礼服和连衣裙购物网站:TFNC London
2018/07/07 全球购物
美国知名眼镜网站:Target Optical
2020/04/04 全球购物
将一个文本文件的内容按倒序打印出来
2015/01/05 面试题
我的中国梦演讲稿小学篇
2014/08/19 职场文书
2014学习十八届四中全会精神思想汇报范文
2014/10/23 职场文书
英语辞职信怎么写
2015/02/28 职场文书
MyBatis配置文件解析与MyBatis实例演示
2022/04/07 Java/Android