2013년 12월 17일 화요일

[Python] GIF 이미지 파이썬 코드로 변환하기

# this code fragment will convert a GIF to python source code
import base64
print "icon='''\\\n" + base64.encodestring(open("icon.gif").read()) + "'''"

# here's the result
icon='''R0lGODdhFQAVAPMAAAQ2PESapISCBASCBMTCxPxmNCQiJJya/ISChGRmzPz+/PxmzDQyZDQyZDQy
ZDQyZCwAAAAAFQAVAAAElJDISau9Vh2WMD0gqHHelJwnsXVloqDd2hrMm8pYYiSHYfMMRm53ULlQ
HGFFx1MZCciUiVOsPmEkKNVp3UBhJ4Ohy1UxerSgJGZMMBbcBACQlVhRiHvaUsXHgywTdycLdxyB
gm1vcTyIZW4MeU6NgQEBXEGRcQcIlwQIAwEHoioCAgWmCZ0Iq5+hA6wIpqislgGhthEAOw==
'''

# to use this in Tkinter:
import Tkinter
root = Tkinter.Tk()
iconImage=Tkinter.PhotoImage(master=root, data=icon)
Tkinter.Button(image=iconImage).pack()

댓글 없음:

댓글 쓰기