开发者

set data as tkinter background?

so i found this code:

import Image,ImageDraw
import cStringIO
from random import randint as rint

def randgradient():
    img = Image.new("RGB", (300,300), "#FFFFFF")
    draw = ImageDraw.Draw(img)

    r,g,b = rint(0,255), rint(0,255), rint(0,255)
    dr = (rint(0,255) - r)/300.
    dg = (rint(0,255) - g)/300.
    db = (rint(0,255) - b)/300.
    for i in range(300):
        r,g,b = r+dr, g+dg, b+db
        draw.line((i,0,i,300), fill=(int(r),int(g),int(b)))

    f = cStringIO.StringIO()
    img.save(f, "PNG")

    print "Content-type: image/png\n"
    f.seek(0)
    print f.read()

if __name__ == "__main__":
    randgradient()

this code has a picture in the memory and im trying to make it a tkinter background with posibly this bit of code:

from Tkinter import *
Admin=Tk()
image1 = PhotoImage(file="f.png")
w = image1.width()
h = image1.height()
Admin.geometry("%dx%d+0+0" % (w, h))
panel1 = Label(Admin, image=image1)
panel1.pack()
Admin.mainloop

it doesn't really matter how i do it 开发者_StackOverflowbut the way just above does not work so how would i go about it?


You can convert an image to a Tk image using PIL's ImageTk module. See the PhotoImage class examples.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜