Hướng dẫn is there a color function in python? - có một chức năng màu trong python?

1

Mới! Lưu câu hỏi hoặc câu trả lời và sắp xếp nội dung yêu thích của bạn. Tìm hiểu thêm.
Learn more.

Từ câu hỏi này, tôi đã học được cách tô màu Python. Tôi đã tìm ra tất cả các mã màu, đừng lo lắng. Dù sao, câu trả lời làm việc cho tôi là ctypes một bởi orip. Có một chút mệt mỏi khi phải nhập

def a_func[handle,color]:
   ctypes.windll.kernel32.SetConsoleTextAttribute[handle, color]

a_func[handle,AQUA]
1 mỗi khi tôi muốn tô màu văn bản. Có cách nào để chuyển đổi nó thành một chức năng không? Tôi không chắc chắn làm thế nào để gửi các biến thông qua các chức năng và không chắc chắn làm thế nào để thực hiện chúng, ngay cả khi tôi đã làm. Cảm ơn trước! -GhostMancer Tất cả những gì quan trọng đối với tôi là nó hoạt động với tôi - Tôi không có kế hoạch cho kịch bản của mình đi. Màu sắc của tôi:
Anyway, the answer that worked for me was the ctypes one by orip. It's a bit tiresome to have to have to type
def a_func[handle,color]:
   ctypes.windll.kernel32.SetConsoleTextAttribute[handle, color]

a_func[handle,AQUA]
1 every time I want to color text. Is there a way to convert it into a function? I'm not sure how to send variables through functions, and not sure how to implement them, even if I did.
Thanks in advance! -ghostmancer All that matters for me is that it works for me - I'm not planning to give my script away. My colors:

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

hỏi ngày 9 tháng 9 năm 2012 lúc 5:14Sep 9, 2012 at 5:14

1

ummm ... nếu tôi hiểu đúng ...

def a_func[handle,color]:
   ctypes.windll.kernel32.SetConsoleTextAttribute[handle, color]

a_func[handle,AQUA]

hoặc thậm chí tốt hơn

colorFunc = ctypes.windll.kernel32.SetConsoleTextAttribute
colorFunc[handle,AQUA]

Đã trả lời ngày 9 tháng 9 năm 2012 lúc 5:17Sep 9, 2012 at 5:17

Joran Beasleyjoran BeasleyJoran Beasley

106K12 Huy hiệu vàng149 Huy hiệu bạc174 Huy hiệu đồng12 gold badges149 silver badges174 bronze badges

1

Không cần tạo một chức năng mới với

def a_func[handle,color]:
   ctypes.windll.kernel32.SetConsoleTextAttribute[handle, color]

a_func[handle,AQUA]
2 hoặc
def a_func[handle,color]:
   ctypes.windll.kernel32.SetConsoleTextAttribute[handle, color]

a_func[handle,AQUA]
3, chỉ cần gán chức năng với một tên dài cho một tên ngắn hơn, ví dụ:

textcolor = ctypes.windll.kernel32.SetConsoleTextAttribute
textcolor[handle, color]

Đã trả lời ngày 9 tháng 9 năm 2012 lúc 5:33Sep 9, 2012 at 5:33

KimvaiskimvaisKimvais

37.4K16 Huy hiệu vàng107 Huy hiệu bạc140 Huy hiệu đồng16 gold badges107 silver badges140 bronze badges

0

Một cách là

def textcolor[handle, color]:
    ctypes.windll.kernel32.SetConsoleTextAttribute[handle, color]

mà bạn gọi như vậy:

textcolor[handle, AQUA]

Đã trả lời ngày 9 tháng 9 năm 2012 lúc 5:17Sep 9, 2012 at 5:17

Joran Beasleyjoran BeasleyRay Toal

106K12 Huy hiệu vàng149 Huy hiệu bạc174 Huy hiệu đồng17 gold badges174 silver badges223 bronze badges

Không cần tạo một chức năng mới với

def a_func[handle,color]:
   ctypes.windll.kernel32.SetConsoleTextAttribute[handle, color]

a_func[handle,AQUA]
2 hoặc
def a_func[handle,color]:
   ctypes.windll.kernel32.SetConsoleTextAttribute[handle, color]

a_func[handle,AQUA]
3, chỉ cần gán chức năng với một tên dài cho một tên ngắn hơn, ví dụ:

f=lambda handle,color:ctypes.windll.kernel32.SetConsoleTextAttribute[handle, color]

Đã trả lời ngày 9 tháng 9 năm 2012 lúc 5:33

KimvaiskimvaisSep 9, 2012 at 5:19

37.4K16 Huy hiệu vàng107 Huy hiệu bạc140 Huy hiệu đồngGodMan

Một cách là2 gold badges23 silver badges39 bronze badges

mà bạn gọi như vậy:

STD_OUTPUT_HANDLE = -11
handle = ctypes.windll.kernel32.GetStdHandle[-STD_OUTPUT_HANDLE]

Ray Toalray ToalNov 13, 2019 at 17:29

84K17 Huy hiệu vàng174 Huy hiệu bạc223 Huy hiệu ĐồngApostolos

Bạn có thể dùng:20 silver badges25 bronze badges

Xem Python: Mẹo và thủ thuật cho các bài viết tương tự.

Đối với pygame và đồ họa khác hoạt động, nó rất hữu ích khi có các hằng số màu giữ các giá trị RGB màu. Tôi không thể tìm thấy bất cứ điều gì như thế này, vì vậy tôi đã tạo một mô -đun color_constants:color_constants module that:

  1. Chứa các hằng số cho 551 màu được đặt tên* [ví dụ, như có tên là Tuples:
    Color = namedtuple['RGB','red, green, blue']
  2. Mở rộng lớp
    def a_func[handle,color]:
       ctypes.windll.kernel32.SetConsoleTextAttribute[handle, color]
    
    a_func[handle,AQUA]
    
    7 để bao gồm một phương pháp để có được màu được định dạng hex:
    class RGB[Color]:
        def hex_format[self]:
            return '#{:02X}{:02X}{:02X}'.format[self.red,self.green,self.blue]
  3. Lưu trữ các hằng số này trong một & nbsp; ________ 18.

Các màu được hiển thị trong bảng bên dưới và mã đầy đủ được hiển thị bên dưới đó.

Tên màuGiá trị hexGiá trị RGBVật mẫu
AliceBlue#F0f8ffRGB [240.248.255]& nbsp;
Antiquewhite#Faebd7RGB [250.235.215]& nbsp;
Antiquewhite1#FfefdbRGB [255.239.219]& nbsp;
Antiquewhite2#EedfccRGB [238.223.204]& nbsp;
Antiquewhite3#Cdc0b0RGB [205.192.176]& nbsp;
Antiquewhite4#8B8378RGB [139.131.120]& nbsp;
Aqua#00ffffRGB [0,255.255]& nbsp;
Aquamarine1#7FFFD4RGB [127.255.212]& nbsp;
Aquamarine2#76EEC6RGB [118.238.198]& nbsp;
Aquamarine3#66CDAARGB [102.205.170]& nbsp;
Aquamarine4#458b74RGB [69.139.116]& nbsp;
Azure1#F0ffffRGB [240.255.255]& nbsp;
Azure2#E0eeeeRGB [224.238.238]& nbsp;
Azure3#C1CDCDRGB [193.205.205]& nbsp;
Azure4#838b8bRGB [131.139.139]& nbsp;
trái chuối#E3CF57RGB [227,207,87]& nbsp;
be#F5f5dcRGB [245.245.220]& nbsp;
Bisque1#FFE4C4RGB [255.228.196]& nbsp;
Bisque2#EED5B7RGB [238.213.183]& nbsp;
Bisque3#CDB79ERGB [205.183.158]& nbsp;
Bisque4#8b7d6bRGB [139.125.107]& nbsp;
màu đen#000000RGB [0,0,0]& nbsp;
màu đen#000000RGB [0,0,0]& nbsp;
màu đen#000000RGB [0,0,0]& nbsp;
màu đen#000000RGB [0,0,0]& nbsp;
màu đen#000000RGB [0,0,0]& nbsp;
màu đen#000000RGB [0,0,0]& nbsp;
màu đen#000000RGB [0,0,0]& nbsp;
màu đen#000000RGB [0,0,0]& nbsp;
Blanchedalmond#FfebcdRGB [255.235.205]& nbsp;
màu xanh da trời#0000ffRGB [0,0,255]& nbsp;
blue2#0000EERGB [0,0,238]& nbsp;
Blue3#0000CDRGB [0,0,0,205]& nbsp;
Blue4#00008bRGB [0,0,139]& nbsp;
Blueviolet#8a2be2RGB [138,43,226]& nbsp;
gạch#9c661fRGB [156.102.31]& nbsp;
nâu#A52A2ARGB [165,42,42]& nbsp;
Brown1#FF4040RGB [255,64,64]& nbsp;
Brown2#EE3B3BRGB [238,59,59]& nbsp;
Brown3#CD3333RGB [205,51,51]& nbsp;
Brown4#8B2323RGB [139,35,35]& nbsp;
gỗ lớn#Deb887RGB [222.184.135]& nbsp;
Burlywood1#Ffd39bRGB [255.211.155]& nbsp;
Burlywood2#EEC591RGB [238.197.145]& nbsp;
Burlywood3#CDAA7DRGB [205.170.125]& nbsp;
Burlywood4#8B7355RGB [139,115,85]& nbsp;
Burntsienna#8a360fRGB [138,54,15]& nbsp;
màu nâu đen bị cháy#8A3324RGB [138,51,36]& nbsp;
xanh chói#5f9ea0RGB [95.158.160]& nbsp;
cadetblue1#98f5ffRGB [152.245.255]& nbsp;
cadetblue2#8EE5EERGB [142.229.238]& nbsp;
cadetblue3#7AC5CDRGB [122.197.205]& nbsp;
cadetblue4#53868bRGB [83.134.139]& nbsp;
Cadmiumorange#FF6103RGB [255,97,3]& nbsp;
Cadmiumyellow#FF9912RGB [255,153,18]& nbsp;
Cà rốt#ED9121RGB [237,145,33]& nbsp;
Chartreuse1#7FFF00RGB [127.255,0]& nbsp;
Chartreuse2#76EE00RGB [118.238,0]& nbsp;
Chartreuse3#66CD00RGB [102.205,0]& nbsp;
Chartreuse4#458b00RGB [69,139,0]& nbsp;
sô cô la#D2691ERGB [210.105,30]& nbsp;
sô cô la1#FF7F24RGB [255,127,36]& nbsp;
sô cô la2#EE7621RGB [238.118.33]& nbsp;
sô cô la3#CD661dRGB [205.102,29]& nbsp;
sô cô la4#8B4513RGB [139,69,19]& nbsp;
coban#3D59ABRGB [61,89,171]& nbsp;
Cobaltgreen#3D9140RGB [61,145,64]& nbsp;
lạnh#808a87RGB [128.138.135]& nbsp;
san hô#FF7F50RGB [255.127,80]& nbsp;
Coral1#FF7256RGB [255,114,86]& nbsp;
Coral2#EE6A50RGB [238,106,80]& nbsp;
Coral3#CD5b45RGB [205,91,69]& nbsp;
Coral4#8b3e2fRGB [139,62,47]& nbsp;
màu xanh hoa ngô đồng#6495edRGB [100.149.237]& nbsp;
Cornsilk1#Fff8dcRGB [255.248.220]& nbsp;
Cornsilk2#EEE8CDRGB [238.232.205]& nbsp;
Cornsilk3#Cdc8b1RGB [205.200.177]& nbsp;
Cornsilk4#8B8878RGB [139.136.120]& nbsp;
Crimson#DC143CRGB [220,20,60]& nbsp;
Cyan2#00eeeeRGB [0,238.238]& nbsp;
Cyan3#00CDCDRGB [0,205.205]& nbsp;
Cyan4#008b8bRGB [0,139.139]& nbsp;
Darkgoldenrod#B8860BRGB [184.134,11]& nbsp;
Darkgoldenrod1#Ffb90fRGB [255,185,15]& nbsp;
Darkgoldenrod2#Ead0eRGB [238,173,14]& nbsp;
Darkgoldenrod3#CD950CRGB [205,149,12]& nbsp;
Darkgoldenrod4#8B6508RGB [139.101,8]& nbsp;
màu xám đen#A9A9A9RGB [169.169.169]& nbsp;
Màu xanh lá cây đậm#006400RGB [0,100,0]& nbsp;
vải kaki màu thẫm#BDB76BRGB [189.183.107]& nbsp;
darkolivegreen#556b2fRGB [85.107,47]& nbsp;
darkolivegreen1#CAFF70RGB [202.255.112]& nbsp;
darkolivegreen2#BCEE68RGB [188.238.104]& nbsp;
darkolivegreen3#A2CD5ARGB [162.205,90]& nbsp;
darkolivegreen4#6e8b3dRGB [110,139,61]& nbsp;
màu cam đậm#Ff8c00RGB [255,140,0]& nbsp;
Darkorange1#FF7F00RGB [255.127,0]& nbsp;
Darkorange2#EE7600RGB [238.118,0]& nbsp;
Darkorange3#CD6600RGB [205.102,0]& nbsp;
Darkorange4#8B4500RGB [139,69,0]& nbsp;
Darkorchid#9932ccRGB [153,50,204]& nbsp;
darkorchid1#Bf3effRGB [191,62,255]& nbsp;
Darkorchid2#B23AEERGB [178,58,238]& nbsp;
Darkorchid3#9A32CDRGB [154,50,205]& nbsp;
Darkorchid4#68228bRGB [104.34.139]& nbsp;
Darksalmon#E9967ARGB [233.150.122]& nbsp;
DarkseaGreen#8fbc8fRGB [143.188.143]& nbsp;
DarkseaGreen1#C1FFC1RGB [193.255.193]& nbsp;
DarkseaGreen2#B4Eeb4RGB [180.238.180]& nbsp;
DarkseaGreen3#9BCD9BRGB [155.205.155]& nbsp;
DarkseaGreen4#698b69RGB [105.139.105]& nbsp;
DarkslateBlue#483d8bRGB [72,61,139]& nbsp;
Darkslategray#2F4F4FRGB [47,79,79]& nbsp;
DarkslateGray1#97ffffRGB [151.255.255]& nbsp;
Darkslategray2#8deeeeRGB [141.238.238]& nbsp;
Darkslategray3#79CDCDRGB [121.205.205]& nbsp;
Darkslategray4#528b8bRGB [82.139.139]& nbsp;
Darkturquoise#00ced1RGB [0,206,209]& nbsp;
màu tím đậm#9400D3RGB [148,0,211]& nbsp;
Deeppink1#FF1493RGB [255,20,147]& nbsp;
Deeppink2#EE1289RGB [238,18,137]& nbsp;
Deeppink3#CD1076RGB [205,16,118]& nbsp;
Deeppink4#8B0A50RGB [139,10,80]& nbsp;
DeepSkyBlue1#00bfffRGB [0,191.255]& nbsp;
DeepskyBlue2#00B2EERGB [0,178.238]& nbsp;
DeepskyBlue3#009ACDRGB [0,154.205]& nbsp;
DeepSkyBlue4#00688bRGB [0,104.139]& nbsp;
Dimgray#696969RGB [105.105.105]& nbsp;
DodgerBlue1#FF3030RGB [255,48,48]& nbsp;
Firebrick2#EE2C2CRGB [238,44,44]& nbsp;
Firebrick2#EE2C2CRGB [238,44,44]& nbsp;
Firebrick2#EE2C2CRGB [238,44,44]& nbsp;
Firebrick2#EE2C2CRGB [238,44,44]& nbsp;
Firebrick2#EE2C2CRGB [238,44,44]& nbsp;
Firebrick3#CD2626RGB [205,38,38]& nbsp;
Firebrick4#8b1a1aRGB [139,26,26]& nbsp;
thịt#FF7D40RGB [255,125,64]& nbsp;
Hoa#Fffaf0RGB [255.250.240]& nbsp;
rừng xanh#228b22RGB [34.139.34]& nbsp;
Gainsboro#DCDCDCRGB [220.220.220]& nbsp;
Ghostwhite#F8f8ffRGB [248.248.255]& nbsp;
Vàng1#FFD700RGB [255,215,0]& nbsp;
Vàng2#EEC900RGB [238.201,0]& nbsp;
Vàng3#CDAD00RGB [205,173,0]& nbsp;
Vàng4#8B7500RGB [139.117,0]& nbsp;
Goldenrod#DAA520RGB [218.165.32]& nbsp;
Goldenrod1#FFC125RGB [255,193,37]& nbsp;
Goldenrod2#EEB422RGB [238,180,34]& nbsp;
Goldenrod3#CD9b1dRGB [205,155,29]& nbsp;
Goldenrod4#8B6914RGB [139.105,20]& nbsp;
xám#808080RGB [128.128.128]& nbsp;
Màu xám1#030303RGB [3,3,3]& nbsp;
Màu xám10#1A1A1ARGB [26,26,26]& nbsp;
Gray11#1C1C1CRGB [28,28,28]& nbsp;
Gray12#1f1f1fRGB [31,31,31]& nbsp;
Gray13#212121RGB [33,33,33]& nbsp;
Gray14#242424RGB [36,36,36]& nbsp;
Gray15#262626RGB [38,38,38]& nbsp;
Gray16#292929RGB [41,41,41]& nbsp;
Gray17#2b2b2bRGB [43,43,43]& nbsp;
Gray18#2E2E2ERGB [46,46,46]& nbsp;
Gray19#303030RGB [48,48,48]& nbsp;
Màu xám2#050505RGB [5,5,5]& nbsp;
Màu xám20#333333RGB [51,51,51]& nbsp;
Gray21#363636RGB [54,54,54]& nbsp;
Gray22#383838RGB [56,56,56]& nbsp;
Gray23#3b3b3bRGB [59,59,59]& nbsp;
Gray24#3D3D3DRGB [61,61,61]& nbsp;
Gray25#404040RGB [64,64,64]& nbsp;
Gray26#424242RGB [66,66,66]& nbsp;
Gray27#454545RGB [69,69,69]& nbsp;
Gray28#474747RGB [71,71,71]& nbsp;
Gray29#4A4A4ARGB [74,74,74]& nbsp;
Màu xám3#080808RGB [8,8,8]& nbsp;
Gray30#4D4D4DRGB [77,77,77]& nbsp;
GRAY31#4f4f4fRGB [79,79,79]& nbsp;
GRAY32#525252RGB [82,82,82]& nbsp;
GRAY33#545454RGB [84,84,84]& nbsp;
GRAY34#575757RGB [87,87,87]& nbsp;
GRAY35#595959RGB [89,89,89]& nbsp;
GRAY36#5C5C5CRGB [92,92,92]& nbsp;
GRAY37#5e5e5eRGB [94,94,94]& nbsp;
GRAY38#616161RGB [97,97,97]& nbsp;
GRAY39#636363RGB [99,99,99]& nbsp;
Gray4#0A0A0ARGB [10,10,10]& nbsp;
Gray40#666666RGB [102.102.102]& nbsp;
GRAY42#6b6b6bRGB [107.107.107]& nbsp;
GRAY43#6e6e6eRGB [110.110.110]& nbsp;
GRAY44#707070RGB [112.112.112]& nbsp;
Gray45#737373RGB [115.115.115]& nbsp;
Gray46#757575RGB [117.117.117]& nbsp;
Gray47#787878RGB [120.120.120]& nbsp;
GRAY48#7a7a7aRGB [122.122.122]& nbsp;
Gray49#7D7D7DRGB [125.125.125]& nbsp;
Gray5#0D0D0DRGB [13,13,13]& nbsp;
GRAY50#7f7f7fRGB [127.127.127]& nbsp;
Gray51#828282RGB [130.130.130]& nbsp;
Gray52#858585RGB [133.133.133]& nbsp;
Gray53#878787RGB [135.135.135]& nbsp;
Gray54#8a8a8aRGB [138.138.138]& nbsp;
Gray55#8c8c8cRGB [140.140.140]& nbsp;
Gray56#8f8f8fRGB [143.143.143]& nbsp;
Gray57#919191RGB [145,145,145]& nbsp;
Gray58#949494RGB [148.148.148]& nbsp;
Gray59#969696RGB [150.150.150]& nbsp;
Màu xám6#0f0f0fRGB [15,15,15]& nbsp;
Gray60#999999RGB [153.153.153]& nbsp;
Gray61#9C9C9CRGB [156.156.156]& nbsp;
Gray62#9e9e9eRGB [158.158.158]& nbsp;
Gray63#A1A1A1RGB [161.161.161]& nbsp;
Gray64#A3A3A3RGB [163.163.163]& nbsp;
Gray65#A6A6A6RGB [166.166.166]& nbsp;
Gray66#A8A8A8RGB [168.168.168]& nbsp;
Gray67#AbababRGB [171.171.171]& nbsp;
Gray68#AdadadRGB [173.173.173]& nbsp;
Gray69#B0B0B0RGB [176.176.176]& nbsp;
Gray7#121212RGB [18,18,18]& nbsp;
Gray70#B3B3B3RGB [179.179.179]& nbsp;
Gray71#B5B5B5RGB [181,181,181]& nbsp;
Gray72#B8B8B8RGB [184.184.184]& nbsp;
Gray73#BababaRGB [186.186.186]& nbsp;
Gray74#BDBDBDRGB [189.189.189]& nbsp;
Gray75#BFBFBFRGB [191.191.191]& nbsp;
Gray76#C2C2C2RGB [194.194.194]& nbsp;
Gray77#C4C4C4RGB [196.196.196]& nbsp;
Gray78#C7C7C7RGB [199.199.199]& nbsp;
Gray79#C9C9C9RGB [201.201.201]& nbsp;
GRAY8#141414RGB [20,20,20]& nbsp;
Màu xám80#CCCCCCRGB [204.204.204]& nbsp;
Màu xám81#CFCFCFRGB [207.207.207]& nbsp;
Màu xám82#D1D1D1RGB [209.209.209]& nbsp;
Màu xám83#D4D4D4RGB [212.212.212]& nbsp;
Màu xám84#D6D6D6RGB [214.214.214]& nbsp;
Màu xám85#D9D9D9RGB [217.217.217]& nbsp;
Màu xám86#DBDBDBRGB [219.219.219]& nbsp;
Màu xám87#DededeRGB [222.222.222]& nbsp;
Màu xám88#E0e0e0RGB [224.224.224]& nbsp;
Màu xám89#E3E3E3RGB [227.227.227]& nbsp;
Màu xám9#171717RGB [23,23,23]& nbsp;
Gray90#E5E5E5RGB [229.229.229]& nbsp;
Gray91#E8e8e8RGB [232.232.232]& nbsp;
Gray92#EbebebRGB [235.235.235]& nbsp;
Gray93#EdedRGB [237.237.237]& nbsp;
Gray94#F0f0f0RGB [240.240.240]& nbsp;
Gray95#F2F2F2RGB [242.242.242]& nbsp;
Gray97#F7F7F7RGB [247.247.247]& nbsp;
GRAY98#FafafaRGB [250.250.250]& nbsp;
Green3#00CD00RGB [0,205,0]& nbsp;
Green4#008B00RGB [0,139,0]& nbsp;
Green4#008B00RGB [0,139,0]& nbsp;
Green4#008B00RGB [0,139,0]& nbsp;
Green4#008B00RGB [0,139,0]& nbsp;
Green4#008B00RGB [0,139,0]& nbsp;
Green4#008B00RGB [0,139,0]& nbsp;
Green4#008B00RGB [0,139,0]& nbsp;
Green4#008B00RGB [0,139,0]& nbsp;
Greenyellow#ADFF2FRGB [173,255,47]& nbsp;
honeydew1#F0fff0RGB [240.255.240]& nbsp;
honeydew2#E0EEE0RGB [224.238.224]& nbsp;
HoneyDew3#C1CDC1RGB [193.205.193]& nbsp;
honeydew4#838b83RGB [131.139.131]& nbsp;
Hotpink#Ff69b4RGB [255.105.180]& nbsp;
hotpink1#Ff6eb4RGB [255.110.180]& nbsp;
hotpink2#EE6AA7RGB [238.106.167]& nbsp;
hotpink3#CD6090RGB [205,96,144]& nbsp;
Hotpink4#8b3a62RGB [139,58,98]& nbsp;
Ấn Độ#CD5c5cRGB [205,92,92]& nbsp;
Ấn Độ1#Ff6a6aRGB [255.106.106]& nbsp;
Ấn Độ2#EE6363RGB [238,99,99]& nbsp;
Ấn Độ3#CD5555RGB [205,85,85]& nbsp;
Ấn Độ4#8b3a3aRGB [139,58,58]& nbsp;
xanh đậm#4B0082RGB [75,0,130]& nbsp;
Ngà1#Fffff0RGB [255.255.240]& nbsp;
Ngà2#Eeeeee0RGB [238.238.224]& nbsp;
Ngà3#CDCDC1RGB [205.205.193]& nbsp;
Ngà4#8b8b83RGB [139.139.131]& nbsp;
ngà voi đen#292421RGB [41,36,33]& nbsp;
ngà voi đen#292421RGB [41,36,33]& nbsp;
khaki#F0E68CRGB [240.230.140]& nbsp;
Khaki1#Fff68fRGB [255.246.143]& nbsp;
khaki2#EEE685RGB [238.230.133]& nbsp;
Khaki3#CDC673RGB [205.198.115]& nbsp;
khaki4#8b864eRGB [139.134,78]& nbsp;
Hoa oải hương#E6e6faRGB [230.230.250]& nbsp;
LAVENDERBLUSH2#Fff0f5RGB [255.240.245]& nbsp;
#EEE0E5RGB [238.224.229]LAVENDERBLUSH3& nbsp;
#Cdc1c5RGB [205.193.197]LAVENDERBLUSH4& nbsp;
#8B8386RGB [139.131.134]Cỏ xanh& nbsp;
#7CFC00RGB [124.252,0]Lemonchiffon1& nbsp;
#FffacdRGB [255.250.205]Lemonchiffon2& nbsp;
#EEE9BFRGB [238.233.191]Lemonchiffon3& nbsp;
#Cdc9a5RGB [205.201.165]Lemonchiffon4& nbsp;
#8B8970RGB [139.137.112]ánh sáng& nbsp;
#Add8e6RGB [173.216.230]LightBlue1& nbsp;
#BFefffRGB [191.239.255]LightBlue2& nbsp;
#B2dfeeRGB [178.223.238]LightBlue3& nbsp;
#9AC0CDRGB [154.192.205]LightBlue4& nbsp;
#68838bRGB [104.131.139]Lightcoral& nbsp;
#F08080RGB [240.128.128]Lightcyan1& nbsp;
#E0ffffRGB [224.255.255]Lightcyan2& nbsp;
#D1eeeeRGB [209.238.238]Lightcyan3& nbsp;
#B4CDCDRGB [180.205.205]Lightcyan4& nbsp;
#7a8b8bRGB [122.139.139]lightgoldenrod1& nbsp;
#Ffec8bRGB [255.236.139]LIGHTGOLDENROD2& nbsp;
#EEDC82RGB [238.220.130]LIGHTGOLDENROD3& nbsp;
#CDBE70RGB [205.190.112]LIGHTGOLDENROD4& nbsp;
#8B814CRGB [139.129,76]Lightgoldenrodyello& nbsp;
#Fafad2RGB [250.250.210]Lightgrey& nbsp;
#D3D3D3RGB [211,211,211]màu hồng nhạt& nbsp;
#Ffb6c1RGB [255.182.193]Lightpink1& nbsp;
#Ffaeb9RGB [255.174.185]Lightpink2& nbsp;
#EEA2ADRGB [238.162.173]Lightpink3& nbsp;
#CD8c95RGB [205.140.149]Lightpink4& nbsp;
#8b5f65RGB [139,95,101]Lightsalmon1& nbsp;
#Ffa07aRGB [255.160.122]Lightsalmon2& nbsp;
#EE9572RGB [238.149.114]Lightsalmon3& nbsp;
#CD8162RGB [205.129,98]Lightsalmon4& nbsp;
#8B5742RGB [139,87,66]Lightreen& nbsp;
#20b2aaRGB [32.178.170]LightskyBlue& nbsp;
#87cefaRGB [135.206.250]LightskyBlue1& nbsp;
#B0e2ffRGB [176.226.255]LightskyBlue2& nbsp;
#A4D3EERGB [164,211,238]LightskyBlue3& nbsp;
#8db6cdRGB [141.182.205]LightskyBlue4& nbsp;
#607b8bRGB [96.123.139]LightslateBlue& nbsp;
#8470ffRGB [132.112.255]LightslateGray& nbsp;
#778899RGB [119.136.153]LightsteelBlue& nbsp;
#B0C4DERGB [176.196.222]LightSteelBlue1& nbsp;
#Cae1ffRGB [202.225.255]lightsteelblue2& nbsp;
#BCD2EERGB [188.210.238]LightSteelBlue3& nbsp;
#A2B5CDRGB [162.181.205]LightSteelBlue4& nbsp;
#6e7b8bRGB [110.123.139]lightyellow1& nbsp;
#Ffffe0RGB [255.255.224]lightyellow2& nbsp;
#EEEED1RGB [238.238.209]lightyellow3& nbsp;
#CDCDB4RGB [205.205.180]lightyellow4& nbsp;
#8b8b7aRGB [139.139.122]Limegreen& nbsp;
#32CD32RGB [50.205,50]lanh& nbsp;
#Faf0e6RGB [250.240.230]Magenta& nbsp;
#Ff00ffRGB [255,0,255]Magenta2& nbsp;
#Ee00eeRGB [238,0,238]Magenta3& nbsp;
#CD00CDRGB [205,0,205]Magenta4& nbsp;
#8b008bRGB [139,0,139]Manganeseblue& nbsp;
#03A89ERGB [3.168.158]Bỏ rơi& nbsp;
#800000RGB [128,0,0]Maroon1& nbsp;
#Ff34b3RGB [255,52,179]Maroon2& nbsp;
#EE30A7RGB [238,48,167]Maroon3& nbsp;
#CD2990RGB [205,41,144]Maroon4& nbsp;
#8b1c62RGB [139,28,98]trung bình& nbsp;
#BA55D3RGB [186,85,211]MediumorChid1& nbsp;
#E066ffRGB [224.102.255]Mediumorchid2& nbsp;
#D15FeeRGB [209,95,238]Mediumorchid3& nbsp;
#B452CDRGB [180,82,205]MediumorChid4& nbsp;
#7A378BRGB [122,55,139]Mediumpurple& nbsp;
MediumTurquoise#48d1ccRGB [72.209.204]& nbsp;
Mediumvioletred#C71585RGB [199,21,133]& nbsp;
dưa gang#E3A869RGB [227.168.105]& nbsp;
màu xanh nửa đêm#191970RGB [25,25,112]& nbsp;
cây bạc hà#BDFCC9RGB [189.252.201]& nbsp;
Mintcream#F5fffaRGB [245.255.250]& nbsp;
Mistyrose1#Ffe4e1RGB [255.228.225]& nbsp;
Mistyrose2#EED5D2RGB [238.213.210]& nbsp;
Mistyrose3#CDB7B5RGB [205.183.181]& nbsp;
Mistyrose4#8b7d7bRGB [139.125.123]& nbsp;
Gianh cao#Ffe4b5RGB [255.228.181]& nbsp;
Navajowhite1#FfdeadRGB [255.222.173]& nbsp;
Navajowhite2#EECFA1RGB [238.207.161]& nbsp;
Navajowhite3#CDB38bRGB [205.179.139]& nbsp;
NAVAJOWHITE4#8B795ERGB [139.121,94]& nbsp;
Hải quân#000080RGB [0,0,128]& nbsp;
Oldlace#Fdf5e6RGB [253.245.230]& nbsp;
Ôliu#808000RGB [128.128,0]& nbsp;
Màu xám ô liu#6b8e23RGB [107,142,35]& nbsp;
OLIVEDRAB1#C0FF3ERGB [192.255,62]& nbsp;
Olivingrab2#B3EE3ARGB [179.238,58]& nbsp;
Olivingrab3#9ACD32RGB [154.205,50]& nbsp;
Olivingrab4#698b22RGB [105.139.34]& nbsp;
trái cam#FF8000RGB [255.128,0]& nbsp;
Orange1#FFA500RGB [255.165,0]& nbsp;
Orange2#EE9A00RGB [238,154,0]& nbsp;
Orange3#CD8500RGB [205,133,0]& nbsp;
Orange4#8B5A00RGB [139,90,0]& nbsp;
Orangered1#FF4500RGB [255,69,0]& nbsp;
Orangered2#EE4000RGB [238,64,0]& nbsp;
Orangered3#CD3700RGB [205,55,0]& nbsp;
Orangered4#8B2500RGB [139,37,0]& nbsp;
Hoa lan#DA70D6RGB [218.112.214]& nbsp;
Hoa lan1#Ff83faRGB [255.131.250]& nbsp;
Hoa lan2#EE7AE9RGB [238.122.233]& nbsp;
Hoa lan3#CD69c9RGB [205.105.201]& nbsp;
Hoa lan#8B4789RGB [139,71,137]& nbsp;
Palegoldenrod#EEE8AARGB [238.232.170]& nbsp;
Palegreen#98FB98RGB [152.251.152]& nbsp;
palegreen1#9aff9aRGB [154.255.154]& nbsp;
palegreen2#90EE90RGB [144.238.144]& nbsp;
Palegreen3#7CCD7CRGB [124.205.124]& nbsp;
palegreen4#548b54RGB [84.139,84]& nbsp;
Paleturquoise1#BBFFFFRGB [187.255.255]& nbsp;
Paleturquoise2#AeeeeeRGB [174.238.238]& nbsp;
Paleturquoise3#96CDCDRGB [150.205.205]& nbsp;
Paleturquoise4#668b8bRGB [102.139.139]& nbsp;
nhợt nhạt#DB7093RGB [219.112.147]& nbsp;
Palevioletred1#Ff82abRGB [255.130.171]& nbsp;
Palevioletred2#Ee799fRGB [238.121.159]& nbsp;
Palevioletred3#CD6889RGB [205.104.137]& nbsp;
Palevioletred4#8B475DRGB [139,71,93]& nbsp;
đu đủ#FFEFD5RGB [255.239.213]& nbsp;
Peachpuff1#Ffdab9RGB [255.218.185]& nbsp;
Peachpuff2#EecbadRGB [238.203.173]& nbsp;
Peachpuff3#CDAF95RGB [205.175.149]& nbsp;
Peachpuff4#8B7765RGB [139.119.101]& nbsp;
con công#33A1C9RGB [51.161.201]& nbsp;
Hồng#Ffc0cbRGB [255.192.203]& nbsp;
Pink1#Ffb5c5RGB [255.181.197]& nbsp;
Pink2#EEA9B8RGB [238.169.184]& nbsp;
Pink3#CD919ERGB [205.145.158]& nbsp;
Pink4#8b636cRGB [139,99,108]& nbsp;
mận#DDA0DDRGB [221.160.221]& nbsp;
mận1#FFBBFFRGB [255.187.255]& nbsp;
mận2#EEAEEERGB [238.174.238]& nbsp;
mận 3#CD96cdRGB [205.150.205]& nbsp;
mận 4#8b668bRGB [139.102.139]& nbsp;
Powderblue#B0E0E6RGB [176.224.230]& nbsp;
màu đỏ tía#800080RGB [128,0,128]& nbsp;
màu tím1#9b30ffRGB [155,48,255]& nbsp;
màu tím2#912CEERGB [145,44,238]& nbsp;
màu tím3#7d26cdRGB [125.38.205]& nbsp;
màu tím4#551A8BRGB [85,26,139]& nbsp;
dâu rừng#872657RGB [135,38,87]& nbsp;
RAWSIENNA#C76114RGB [199,97,20]& nbsp;
Red1#FF0000RGB [255,0,0]& nbsp;
Đỏ 2#EE0000RGB [238,0,0]& nbsp;
Red3#CD0000RGB [205,0,0]& nbsp;
Red4#8B0000RGB [139,0,0]& nbsp;
Rosybrown#BC8F8FRGB [188.143.143]& nbsp;
RosyBrown1#Ffc1c1RGB [255.193.193]& nbsp;
Rosybrown2#EEB4B4RGB [238.180.180]& nbsp;
Rosybrown3#CD9b9bRGB [205.155.155]& nbsp;
Rosybrown4#8B6969RGB [139.105.105]& nbsp;
xanh đậm#4169e1RGB [65.105.225]& nbsp;
RoyalBlue1#4876ffRGB [72.118.255]& nbsp;
RoyalBlue2#436eeeRGB [67.110.238]& nbsp;
RoyalBlue3#3A5FCDRGB [58,95,205]& nbsp;
RoyalBlue4#27408bRGB [39,64,139]& nbsp;
Cá hồi#FA8072RGB [250.128.114]& nbsp;
Cá hồi1#FF8C69RGB [255.140.105]& nbsp;
Cá hồi2#EE8262RGB [238,130,98]& nbsp;
Cá hồi3#CD7054RGB [205.112,84]& nbsp;
Cá hồi4#8B4C39RGB [139,76,57]& nbsp;
Sandybrown#F4A460RGB [244.164,96]& nbsp;
Sapgreen#308014RGB [48.128,20]& nbsp;
Biển1#54ff9fRGB [84.255.159]& nbsp;
Biển2#4EEE94RGB [78.238.148]& nbsp;
BEAGREEN3#43CD80RGB [67.205.128]& nbsp;
BEAGREEN4#2E8B57RGB [46.139,87]& nbsp;
Vỏ sò1#Fff5eeRGB [255.245.238]& nbsp;
Vỏ sò2#EEE5DERGB [238.229.222]& nbsp;
Vỏ sò3#Cdc5bfRGB [205.197.191]& nbsp;
Vỏ sò4#8B8682RGB [139.134.130]& nbsp;
SEPIA#5E2612RGB [94,38,18]& nbsp;
sgibeet#8E388ERGB [142,56,142]& nbsp;
sgibrightgray#C5C1AARGB [197,193,170]& nbsp;
Sgichartreuse#71C671RGB [113.198.113]& nbsp;
Sgidarkgray#555555RGB [85,85,85]& nbsp;
sgigray12#1E1E1ERGB [30,30,30]& nbsp;
sgigray16#282828RGB [40,40,40]& nbsp;
sgigray32#515151RGB [81,81,81]& nbsp;
sgigray36#5b5b5bRGB [91,91,91]& nbsp;
sgigray52#848484RGB [132.132.132]& nbsp;
sgigray56#8e8e8eRGB [142.142.142]& nbsp;
sgigray72#B7B7B7RGB [183.183.183]& nbsp;
sgigray76#C1C1C1RGB [193.193.193]& nbsp;
sgigray92#EaeaeaRGB [234.234.234]& nbsp;
sgigray96#F4f4f4RGB [244.244.244]& nbsp;
sgilightblue#7d9ec0RGB [125.158.192]& nbsp;
sgilightgray#AaaaaaRGB [170.170.170]& nbsp;
Sgiolivevivingrab#8E8E38RGB [142,142,56]& nbsp;
Sgisalmon#C67171RGB [198.113.113]& nbsp;
sgislateBlue#7171c6RGB [113.113.198]& nbsp;
sgiteal#388e8eRGB [56.142.142]& nbsp;
Sienna#A0522DRGB [160,82,45]& nbsp;
Sienna1#FF8247RGB [255,130,71]& nbsp;
Sienna2#EE7942RGB [238,121,66]& nbsp;
Sienna3#CD6839RGB [205.104,57]& nbsp;
Sienna4#8B4726RGB [139,71,38]& nbsp;
màu bạc#C0C0C0RGB [192.192.192]& nbsp;
trời xanh#87CeebRGB [135.206.235]& nbsp;
SkyBlue1#87ceffRGB [135.206.255]& nbsp;
Skyblue2#7ec0eeRGB [126.192.238]& nbsp;
Skyblue3#6CA6CDRGB [108.166.205]& nbsp;
Skyblue4#4A708BRGB [74.112.139]& nbsp;
màu xanh đá phiến#6a5acdRGB [106,90,205]& nbsp;
SlateBlue1#836fffRGB [131.111.255]& nbsp;
SlateBlue2#7a67eeRGB [122.103.238]& nbsp;
SlateBlue3#6959cdRGB [105,89,205]& nbsp;
SlateBlue4#473c8bRGB [71,60,139]& nbsp;
phiến đá xám#708090RGB [112.128.144]& nbsp;
slategray1#C6E2ffRGB [198,226.255]& nbsp;
slategray2#B9D3EERGB [185.211.238]& nbsp;
slategray3#9fb6cdRGB [159.182.205]& nbsp;
slategray4#6c7b8bRGB [108.123.139]& nbsp;
tuyết1#FffafaRGB [255.250.250]& nbsp;
Tuyết2#EEE9E9RGB [238.233.233]& nbsp;
Tuyết3#Cdc9c9RGB [205.201.201]& nbsp;
Snow4#8B8989RGB [139.137.137]& nbsp;
Xuân xanh#00ff7fRGB [0,255.127]& nbsp;
SpringGreen1#00EE76RGB [0,238.118]& nbsp;
Springgreen2#00CD66RGB [0,205.102]& nbsp;
Springgreen3#008B45RGB [0,139,69]& nbsp;
màu xanh thép#4682b4RGB [70.130.180]& nbsp;
SteelBlue1#63b8ffRGB [99.184.255]& nbsp;
SteelBlue2#5caceeRGB [92.172.238]& nbsp;
SteelBlue3#4f94cdRGB [79.148.205]& nbsp;
Thép 4#36648bRGB [54.100.139]& nbsp;
làn da rám nắng#D2B48CRGB [210.180.140]& nbsp;
tan1#Ffa54fRGB [255.165,79]& nbsp;
tan2#EE9A49RGB [238.154,73]& nbsp;
tan3#CD853FRGB [205,133,63]& nbsp;
tan4#8b5a2bRGB [139,90,43]& nbsp;
teal#008080RGB [0,128.128]& nbsp;
Thánh địa#D8BFD8RGB [216.191.216]& nbsp;
Thistle1#Ffe1ffRGB [255.225.255]& nbsp;
Thistle2#Eed2eeRGB [238.210.238]& nbsp;
Thistle3#CDB5CDRGB [205.181.205]& nbsp;
Thistle4#8b7b8bRGB [139.123.139]& nbsp;
Cà chua1#FF6347RGB [255,99,71]& nbsp;
Cà chua2#EE5C42RGB [238,92,66]& nbsp;
Cà chua3#CD4f39RGB [205,79,57]& nbsp;
Cà chua4#8B3626RGB [139,54,38]& nbsp;
màu ngọc lam#40e0d0RGB [64.224.208]& nbsp;
Ngọc lam1#00f5ffRGB [0,245.255]& nbsp;
màu ngọc lam2#00e5eeRGB [0,229.238]& nbsp;
màu ngọc lam3#00C5CDRGB [0,197.205]& nbsp;
TURQUOISE4#00868bRGB [0,134.139]& nbsp;
Turquoiseblue#00c78cRGB [0,199,140]& nbsp;
màu tím#EE82EERGB [238.130.238]& nbsp;
Violetred#D02090RGB [208.32.144]& nbsp;
Violetred1#Ff3e96RGB [255,62,150]& nbsp;
Violetred2#EE3A8CRGB [238,58,140]& nbsp;
Violetred3#CD3278RGB [205,50,120]& nbsp;
Violetred4#8B2252RGB [139,34,82]& nbsp;
Warmgrey#808069RGB [128.128.105]& nbsp;
lúa mì#F5DEB3RGB [245.222.179]& nbsp;
Lúa mì1#Ffe7baRGB [255.231.186]& nbsp;
lúa mì2#Eed8aeRGB [238.216.174]& nbsp;
lúa mì3#CDBA96RGB [205.186.150]& nbsp;
lúa mì4#8b7e66RGB [139.126.102]& nbsp;
trắng#FFFFFFRGB [255.255.255]& nbsp;
khói trắng#F5F5F5RGB [245.245.245]& nbsp;
vàng1#FFFF00RGB [255.255,0]& nbsp;
vàng2#EEEE00RGB [238,238,0]& nbsp;
vàng3#CDCD00RGB [205.205,0]& nbsp;
vàng4#8b8b00RGB [139.139,0]& nbsp;

color_constants.py

def a_func[handle,color]:
   ctypes.windll.kernel32.SetConsoleTextAttribute[handle, color]

a_func[handle,AQUA]
0

*Cảm ơn cloford.com cho tất cả các tên màu.

Những bài viết liên quan

  1. Sửa lỗi WebVTT với Python
  2. Sử dụng Python để chuyển đổi hình ảnh sang trang web
  3. Ký hiệu khoa học trong Python
  4. Hiểu Python từ __main__ biến
  5. Chuyển đổi các tab hàng đầu sang không gian với Python
  6. pow [x, y, z] hiệu quả hơn x ** y % z và các tùy chọn khác
  7. Một mô hình Python cho các trận đấu bóng bàn
  8. Chuyển đổi số lượng lớn các tệp Python sang các tệp Notebook Ipython [chuyển đổi PY sang IPynb]
  9. Python sườn ngày.strftime [] chậm hơn str [], chia, giải nén và concatenate?
  10. Bài tập lập trình Python cơ bản: Một xu tăng gấp đôi mỗi ngày
  11. Từ điển hai chiều trong Python
  12. Cách tìm tất cả các cài đặt Python của bạn trên Windows [và Mac]
  13. Liên kết các tệp python với nhàn rỗi
  14. Thay đổi khoảng thời gian tự động mặc định trong Jupyterlab
  15. Python: isdigit [] so với isdecimal []
  16. Đồng hồ Python giải thích
  17. Mô -đun hằng số màu Python [Bài viết này]
  18. Độ sâu đệ quy tối đa vượt quá trong khi gọi đối tượng Python
  19. Khi nào nên sử dụng các phương thức tĩnh trong Python? Không bao giờ
  20. Cuối cùng, một trường hợp sử dụng cho cuối cùng - Xử lý ngoại lệ Python
  21. Tạo một công cụ trang trí email với Python và AWS
  22. Thử thách mã hóa Python: Hai người có cùng sinh nhật
  23. Cách tạo mô phỏng đơn giản trong dữ liệu Python - Số
  24. Trình đoán Collatz trong Python
  25. Tập lệnh python đơn giản để trích xuất văn bản từ tệp srt
  26. Môi trường ảo Python với VENV
  27. Ánh xạ Python đến Python 3 trên máy Mac của bạn
  28. Cách biến Idle thành trình soạn thảo mặc định cho các tệp Python trên Windows
  29. Cách thực hiện nhiệm vụ vận hành ternary trong Python
  30. Cách chuyển đổi giây thành năm với Python
  31. Cách tạo gói Python
  32. Cách đọc tệp có Python
  33. Cách kiểm tra hệ điều hành với Python
  34. Cách sử dụng Enumerate [] để in danh sách được đánh số trong Python
  35. Cách liên tục nối vào một chuỗi trong Python
  36. Kiểm tra trang web của bạn để biết các liên kết bị hỏng với Python
  37. Cách thực hiện nhiệm vụ đồng thời trong Python
  38. Visual Studio Code - Mở tệp với Python Open []
  39. Cách cắt dây trong Python
  40. Làm thế nào Python tìm thấy các mô -đun nhập khẩu
  41. Cách hợp nhất từ ​​điển trong Python
  42. Cách lập chỉ mục chuỗi trong Python
  43. Làm thế nào để tạo một tuple trong Python

Có mô -đun màu trong Python không?

Mô -đun TermColor là một mô -đun Python cho định dạng màu ANSII cho đầu ra trong thiết bị đầu cuối. Ví dụ: Chương trình Python để in văn bản và nền màu.. Example: Python program to print colored text and background.

Làm thế nào để bạn tô màu trong Python?

Để làm cho một số văn bản của bạn dễ đọc hơn, bạn có thể sử dụng mã thoát ANSI để thay đổi màu của đầu ra văn bản trong chương trình Python của bạn.... Thêm màu vào văn bản trong Python ..

Làm cách nào để có được màu RGB trong Python?

# Trong Python, màu sắc chỉ có thể được lưu trữ dưới dạng 3 lớp [đỏ, xanh lá cây, xanh dương].red = [255,0,0] màu xanh lá cây = [0,255,0] blue = [0,0,255] # Nhiều thư viện làm việc với những điều này.# Bạn cũng có thể xác định các chức năng của riêng bạn để làm việc với chúng.colors can just be stored as 3-Tuples of [Red, Green, Blue]. red = [255,0,0] green = [0,255,0] blue = [0,0,255] # Many libraries work with these. # You can also, of course, define your own functions to work with them.

Làm cách nào để in văn bản màu trong Python?

#Import các mô -đun cần thiết.Từ nhập khẩu màu FG, BG, attr.#Đặt giá trị văn bản.Text = "Lập trình Python" ....
#Mô -đun màu từ TermColor.Từ nhập khẩu termcolor màu.#Set các giá trị chuỗi.Text1 = "Tìm hiểu" ....
#Hình ảnh mô -đun cần thiết.Từ nhập khẩu Colorama trở lại, trước, phong cách.#Văn bản in với màu nền ..

Bài Viết Liên Quan

Chủ Đề