Python中的颜色函数

2024-04-28 23:18:37 发布

您现在位置:Python中文网/ 问答频道 /正文

this question我学会了如何给Python上色。我查清楚了所有的色码,别担心。
不管怎样,对我有效的答案是orip的ctypes。每次我想给文本上色时都要输入ctypes.windll.kernel32.SetConsoleTextAttribute(handle, AQUA)有点累。有没有办法把它转换成函数?我不知道如何通过函数发送变量,也不知道如何实现它们,即使我这样做了。
提前谢谢!-鬼怪 对我来说,重要的是它对我有用-我不打算把我的剧本给别人。 我的颜色:

BLACK    = 0x0000
BLUE    = 0x0001
GREEN    = 0x0002
RED    = 0x0004
PURPLE    = 0x0005
YELLOW    = 0x0006
WHITE    = 0x0007
GRAY    = 0x0008
GREY    = 0x0008
AQUA    = 0x0009 #Very Blue

Tags: 函数答案文本thisctypeshandlequestion学会
3条回答

无需使用deflambda创建新函数,只需将具有长名称的函数分配给较短名称,例如:

textcolor = ctypes.windll.kernel32.SetConsoleTextAttribute
textcolor(handle, color)

一种方法是

def textcolor(handle, color):
    ctypes.windll.kernel32.SetConsoleTextAttribute(handle, color)

你这样称呼:

textcolor(handle, AQUA)

嗯。。。如果我理解正确。。。

def a_func(handle,color):
   ctypes.windll.kernel32.SetConsoleTextAttribute(handle, color)

a_func(handle,AQUA)

或者更好

colorFunc = ctypes.windll.kernel32.SetConsoleTextAttribute
colorFunc(handle,AQUA)

相关问题 更多 >