or if using Linux install with
sudo apt install imagemagick
Example code with instructions:
from fltk import *
#xbm is monochrome but xpm has color :)
#use imagemagick software to convert png to xpm
# convert -resize 60x43 smilycat.png smilycat.xpm
#then copy/paste the xpm data to your python source code as a list
#edit the image data as shown below
'''
Required edits of xpm data in python source code file.
1) Remove the following 3 lines from the top of the data
/* XPM */
static char *smilycat[] = {
/* columns rows colors chars-per-pixel */
2) Remove the following line from the middle of the data
/* pixels */
3) Replace the following line from the end of the data
};
with a list close bracket
]
4) Insert a list variable line at top of data
for example: smilycat_bits=[
'''
smilycat_bits=[
"60 43 229 2 ",
" c #0B0C0B",
". c #1B140E",
"X c #19140F",
"o c #0D1012",
"O c #131413",
"+ c #191611",
"@ c #1B1A14",
"# c #1B1C1B",
"$ c #15191A",
"% c #120F0E",
"& c #23170D",
"* c #251A0E",
"= c #2C1B0D",
"- c #281E14",
"; c #361E10",
": c #37230D",
"> c #24221D",
", c #2A2419",
"< c #362D1E",
"1 c #392712",
"2 c #2E200F",
"3 c #1F2120",
"4 c #272928",
"5 c #3B3527",
"6 c #343535",
"7 c #393B3A",
"8 c #363837",
"9 c #2F3130",
"0 c #4C2C0C",
"q c #44240B",
"w c #532E0B",
"e c #5C260D",
"r c #54310D",
"t c #5C370B",
"y c #462D11",
"u c #4A3214",
"i c #66380B",
"p c #733D09",
"a c #69250C",
"s c #453A29",
"d c #583F22",
"f c #682F29",
"g c #5D431B",
"h c #74440D",
"j c #7B470B",
"k c #654618",
"l c #764C14",
"z c #5A462B",
"x c #5F5035",
"c c #4B412C",
"v c #674B29",
"b c #6D5126",
"n c #654D34",
"m c #635236",
"M c #695739",
"N c #745831",
"B c #7D653F",
"V c #494948",
"C c #5C5446",
"Z c #585A59",
"A c #594E43",
"S c #625B4E",
"D c #5F605F",
"F c #796B4A",
"G c #616454",
"H c #686A5B",
"J c #6D664E",
"K c #666A69",
"L c #6C7166",
"P c #6B7A74",
"I c #6A7673",
"U c #757776",
"Y c #71716A",
"T c #B32E08",
"R c #C93308",
"E c #C83D37",
"W c #884C0A",
"Q c #984E0A",
"! c #92520C",
"~ c #9B560B",
"^ c #995D19",
"/ c #855015",
"( c #A55D0A",
") c #A85C08",
"_ c #B75D08",
"` c #9D6117",
"' c #A8620A",
"] c #BD6B0A",
"[ c #B76608",
"{ c #A6681A",
"} c #B26C15",
"| c #BE7011",
" . c #945C20",
".. c #8E632A",
"X. c #996627",
"o. c #8C6835",
"O. c #97723D",
"+. c #BA792B",
"@. c #A67632",
"#. c #C26C06",
"$. c #C36E09",
"%. c #C86E06",
"&. c #D56C06",
"*. c #CE7205",
"=. c #CB7209",
"-. c #DD7A06",
";. c #D87505",
":. c #D77E16",
">. c #E47303",
",. c #EB7602",
"<. c #E47D04",
"1. c #EA7B06",
"2. c #F27901",
"3. c #F17D09",
"4. c #E07F1A",
"5. c #D14039",
"6. c #866E44",
"7. c #8A744B",
"8. c #93774A",
"9. c #8E7A53",
"0. c #927D55",
"q. c #997F55",
"w. c #D2524D",
"e. c #75817E",
"r. c #B4853E",
"t. c #CC8109",
"y. c #D08309",
"u. c #EB8204",
"i. c #E5810A",
"p. c #F38503",
"a. c #F98701",
"s. c #FE8B01",
"d. c #F78908",
"f. c #FD9509",
"g. c #F18E12",
"h. c #FB9516",
"j. c #ED8112",
"k. c #FEA30A",
"l. c #FFAA17",
"z. c #DA9537",
"x. c #CB8C35",
"c. c #F29722",
"v. c #FEA429",
"b. c #F9A738",
"n. c #FAB032",
"m. c #9C8355",
"M. c #968057",
"N. c #A6864E",
"B. c #B78E47",
"V. c #A58A57",
"C. c #B28D51",
"Z. c #B1945C",
"A. c #B99759",
"S. c #B69352",
"D. c #BC9C62",
"F. c #B49765",
"G. c #AF9367",
"H. c #BDA273",
"J. c #C49954",
"K. c #D3A554",
"L. c #F0AF4B",
"P. c #C09F62",
"I. c #C5A365",
"U. c #CCA868",
"Y. c #D6AC66",
"T. c #D7B16D",
"R. c #DCB671",
"E. c #C9AD7A",
"W. c #E1B169",
"Q. c #ECBC6A",
"!. c #E6B665",
"~. c #F4BF6F",
"^. c #FBBF61",
"/. c #E5BC74",
"(. c #E8BE75",
"). c #F5BF70",
"_. c #F5C06F",
"`. c #FBC56D",
"'. c #ECC37A",
"]. c #E9C076",
"[. c #F6C372",
"{. c #F8C575",
"}. c #F5CA7D",
"|. c #FACC7D",
" X c #F5C778",
".X c #FFD07F",
"XX c #7B8986",
"oX c #7E9290",
"OX c #858988",
"+X c #839493",
"@X c #899796",
"#X c #919292",
"$X c #999C9C",
"%X c #889090",
"&X c #96A4A3",
"*X c #8DA2A1",
"=X c #A1A2A2",
"-X c #AAABAA",
";X c #A4ABAB",
":X c #ADAFB1",
">X c #AEB7B7",
",X c #B9BABA",
"<X c #DABC86",
"1X c #BFC0BF",
"2X c #E8C68A",
"3X c #FCCE80",
"4X c #F1CD89",
"5X c #FED182",
"6X c #FBD38A",
"7X c #FAD693",
"8X c #F6D294",
"9X c #F2CF93",
"0X c #ADC6C7",
"qX c #B7C5C6",
"wX c #BDD0D1",
"eX c #C6C7C7",
"rX c #C5D7D9",
"tX c #DBDCDC",
"yX c #D3D7D7",
"uX c #D8E5E6",
"iX c #E2E3E3",
"pX c #EAEBEB",
"aX c #E6EFEF",
"sX c #EDF2F3",
"dX c #F3F4F4",
"fX c #F4FCFC",
"gX c #FFFFFF",
"hX c #EDEFF0",
"jX c None",
"jXjXjXjXjXjXjXjXjXjX> 5 , jXjXjXjXjXjXjXjXjXjXO + # @ @ O jXjXjXjXjXjXjXjXjXjX> 5 > jXjXjXjXjXjXjXjXjXjXjXjXjXjXjXjXjXjX",
"jXjXjXjXjXjXjXjXjXjXb K.B.7.x 5 4 jXjXjX@ s M 9.V.Z.F.V.9.M s # jXjXjX> s M 8.S.K.k jXjXjXjXjXjXjXjXjXjXjXjXjXjXjXjXjXjX",
"jXjXjXjXjXjXjXjXjXjXh k.k.l.n.L.C.5 # M S.!.L.n.v.v.v.v.b.L.L.V.M @ 5 S.L.n.l.k.k.k jXjXjXjXjXjXjXjXj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.~.~.~.~.~.~.~.).[.6.OXdXdXgXgX-X-XgXgXgXtXZ V #X7 a ,.2.,._ 0 = & & X ",
"jX9 eXiXZ 1X#XfXgXgX%X-XgXgX%XiXiXA K.).~.~.).).~.~.~.~.~.~.~.~._.J.C pXtX$XgXgX=X$XgXgXdX#X,XZ pX1Xs >.2.2.>.Q ; & & $ ",
"jXV dX-XU iXY dXgXgXOX-XgXgXY yXgXOX8.[.).).).).).).).).).).).).{.6.#XgXeXU gXgX=X$XgXgXpXK pXK :XhXc W _ _ ) w & . X jX",
"jXZ iXU #XyXD tXpXpXOX$XpXiXK eXpX;Xn W.W.W.W.W.W.W.W.W.W.W.W.W.W.n :XpX,XK pXpX#X#XpXpXyXD tXOXOXtXZ O - - * O O O jXjX",
"jX3 8 3 4 8 # 8 8 8 4 4 7 8 # 9 7 9 & < < < < < < < < < < < < < < + 9 7 9 # 7 7 4 4 8 8 8 & 6 4 4 6 # jXjXjXjXjXjXjXjXjX"
]
catpix=Fl_Pixmap(smilycat_bits)
win=Fl_Window(100,100)
win.begin()
but=Fl_Button(10,10, 80,60)
but.image(catpix)
win.end()
win.show()
Fl.run()
Output:
Original png image: