I used to this code for a splash screen but doesn't run. Please could someone assist. Or help with a link I can check Tkinter splash screens.
from Tkinter import *
try:
from PIL import Image, ImageTk
except ImportError:
import Image, ImageTk
class SplashScreen(Toplevel):
def __init__(self, master, image=None, timeout=1000):
"""(master, image, timeout=1000) -> create a splash screen
from specified image file. Keep splashscreen up for timeout
milliseconds"""
Toplevel.__init__(self, master, relief=RAISED, borderwidth=5)
self.main = master
if self.main.master != None: # Why ?
self.main.master.withdraw()
self.main.withdraw()
self.overrideredirect(1)
im = Image.open(image)
self.image = ImageTk.PhotoImage(im)
self.after_idle(self.centerOnScreen)
self.update()
self.after(timeout, self.destroy)
def centerOnScreen(self):
self.update_idletasks()
width, height = self.width, self.height = \
self.image.width(), self.image.height()
xmax = self.winfo_screenwidth()
ymax = self.winfo_screenheight()
x0 = self.x0 = (xmax - self.winfo_reqwidth()) / 2 - width/2
y0 = self.y0 = (ymax - self.winfo_reqheight()) / 2 - height/2
self.geometry("+%d+%d" % (x0, y0))
self.createWidgets()
def createWidgets(self):
# Need to fill in here
self.canvas = Canvas(self, height=self.width, width=self.height)
self.canvas.create_image(0,0, anchor=NW, image=self.image)
self.canvas.pack()
def destroy(self):
self.main.update()
self.main.deiconify()
self.withdraw()
if __name__ == "__main__":
import os
tk = Tk()
l = Label(tk, text="Phone Book")
l.pack()
n = Label(tk,text="Name")
n.pack()
E1=Entry(tk,width=40)
E1.grid(row=1,column=0)
E1.pack()
b = Button(tk,width=40)
b.grid(row=1,column=0)
s = Label(tk,text="Surname")
E2=Entry(tk,width=40)
E2.grid(row=1,column=0)
E2.pack()
nr = Label(tk,text="Number")
E3=Entry(tk,width=40)
E3.grid(row=1,column=0)
E3.pack()
assert os.path.exists("python.jpg")
s = SplashScreen(tk, timeout=5000, image="python.jpg")
mainloop()