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

通过对 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 打印自己设计的字体内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!

(0)

相关推荐

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

    通过对 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..###

  • python中tkinter的应用:修改字体的实例讲解

    参考链接:tkinter book font字体的参数有如下6个 family: 字体类别,如'Fixdsys' size: 作为一个整数,以点字体的高度.为了获得字体的n个像素高,使用-n. weight: "BOLD" 表示加粗, "NORMAL" 表示正常大小,默认是NORMAL slant:斜体(默认正常), "NORMAL"表示正常,"ITALIC"表示字体倾斜 underline:下划线,1表示添加下滑线,0表示没

  • 利用python将pdf输出为txt的实例讲解

    一个礼拜前一个同学问我这个事情,由于之前在参加华为的比赛,所以赛后看了一下,据说需要用到pdfminer这个包.于是安装了一下,安装过程很简单: sudo pip install pdfminer; 中间也没有任何的报错.至于如何调用,本人也没有很好的研究过pdfminer这个库,于是开始了百度-- 官方文档:http://www.unixuser.org/~euske/python/pdfminer/index.html 完全使用python编写. (适用于2.4或更新版本) 解析,分析,并转

  • python XlsxWriter模块创建aexcel表格的实例讲解

    安装使用pip install XlsxWriter来安装,Xlsxwriter用来创建excel表格,功能很强大,下面具体介绍: 1.简单使用excel的实例: #coding:utf-8 import xlsxwriter workbook = xlsxwriter.Workbook('d:\\suq\\test\\demo1.xlsx') #创建一个excel文件 worksheet = workbook.add_worksheet('TEST') #在文件中创建一个名为TEST的shee

  • Python使用pandas处理CSV文件的实例讲解

    Python中有许多方便的库可以用来进行数据处理,尤其是Numpy和Pandas,再搭配matplot画图专用模块,功能十分强大. CSV(Comma-Separated Values)格式的文件是指以纯文本形式存储的表格数据,这意味着不能简单的使用Excel表格工具进行处理,而且Excel表格处理的数据量十分有限,而使用Pandas来处理数据量巨大的CSV文件就容易的多了. 我用到的是自己用其他硬件工具抓取得数据,硬件环境是在Linux平台上搭建的,当时数据是在运行脚本后直接输出在termin

  • 对Python 3.2 迭代器的next函数实例讲解

    在python中,使用iter函数可以获得有序聚合类型的迭代器,我个人将迭代器理解为带有next指针的单向链表,获取到的迭代器为链表的表头,表头内容为空,next指针指向有序聚合类型的第一个元素.在访问链表最后一个元素的next指针时,python会报错StopIteration. Python3.x以上的版本在使用next函数时需要注意的是:next()函数在3.x以上的版本更改为__next__(). 使用for迭代器打印文件中的内容的代码如下: file_obj=open(r'E:\Pro

  • Python字典实现简单的三级菜单(实例讲解)

    如下所示: data = { "北京":{ "昌平":{"沙河":["oldboy","test"],"天通苑":["链接地产","我爱我家"]}, "朝阳":{"望京":["奔驰","陌陌"],"国贸":["CICC",&quo

  • Python之自动获取公网IP的实例讲解

    0.预备知识 0.1 SQL基础 ubuntu.Debian系列安装: root@raspberrypi:~/python-script# apt-get install mysql-server Redhat.Centos 系列安装: [root@localhost ~]# yum install mysql-server 登录数据库 pi@raspberrypi:~ $ mysql -uroot -p -hlocalhost Enter password: Welcome to the Ma

  • python django使用haystack:全文检索的框架(实例讲解)

    haystack:全文检索的框架 whoosh:纯Python编写的全文搜索引擎 jieba:一款免费的中文分词包 首先安装这三个包 pip install django-haystack pip install whoosh pip install jieba 1.修改settings.py文件,安装应用haystack, 2.在settings.py文件中配置搜索引擎 HAYSTACK_CONNECTIONS = { 'default': { # 使用whoosh引擎 'ENGINE': '

  • python 3.6 +pyMysql 操作mysql数据库(实例讲解)

    版本信息:python:3.6 mysql:5.7 pyMysql:0.7.11 ################################################################# #author: 陈月白 #_blogs: http://www.cnblogs.com/chenyuebai/ ################################################################# # -*- coding: utf-8

随机推荐