import mtTkinter as Tkinter
import ttk,threading,Image,ImageTk,tkMessageBox,Queue
#Tk
MAXCOUNT = 100
IMAGE_LABEL = 'anonymous.jpg'
#messageBox
MESSAGE = "proceso terminado"
TITLE = "completado"
class changeState(threading.Thread):
def __init__(self,value,progres,label,msg):
threading.Thread.__init__(self)
self._value = value
self._progres = progres
self._label = label
self._msg = msg
def run(self):
self._progres["value"] = self._value
self._label.set(str(self._value)+"%")
if self._value == MAXCOUNT:self._msg()
class windowLoader(Tkinter.Tk):
def __init__(self):
Tkinter.Tk.__init__(self)
self.geometry("400x400")
lista = ("createImage","label","progresbar")
for i in lista:
getattr(self,i)()
def label(self):
self.v = Tkinter.StringVar()
self.v.set("0%")
label_1 = Tkinter.Label(self,image=self.image)
label_1.pack(fill=Tkinter.BOTH,expand=True)
label_2 = Tkinter.Label(label_1,textvariable=self.v)
label_2.pack(side="bottom")
def msg(self):
msgbox = tkMessageBox.showinfo(TITLE,MESSAGE)
self.quit()
def change(self,value):
state = changeState(value,self.progres,self.v,self.msg)
state.daemon = True
state.start()
def createImage(self):
openImage = Image.open(IMAGE_LABEL)
self.image = ImageTk.PhotoImage(openImage)
def progresbar(self):
self.progres = ttk.Progressbar(self,length=1,maximum=MAXCOUNT)
self.progres.pack(fill=Tkinter.X)
class threadLoader(threading.Thread):
def __init__(self,q):
threading.Thread.__init__(self)
self.q = q
def run(self):
root = windowLoader()
self.q.put(root)
root.mainloop()
def loader():
q = Queue.Queue()
call = threadLoader(q)
call.start()
instance = q.get()
return instance
Example:
import loaderTk,time
loader = loader()
for i in range(100):
loader.change(i+1)
time.sleep(0.1)
0 comentarios:
Publicar un comentario