A ver si me podéis echar una mano que tengo que entregar la practica este finde, gracias
Código:
################################# #Videoclub from Tkinter import * import urllib import Image import ImageTk import random class Movie: def __init__(self,title="emptyTitle", director=["emptyDirector"], cast = ["emptyCast"], producer = ["emptyProducer"], writer = ["emptyWriter"], country = ["emptyCountry"], language = ["emptyLanguage"], year = "emptyYear", genres = ["emptyGenres"], votes = "emptyVotes", rating = "emptyRating", runtime = ["emptyRuntime"], plot = ["emptyPlot"], cover_url = "emptyCorver"): self.title = title self.director = director self.cast = cast self.producer = producer self.writer = writer self.country = country self.language = language self.year = year self.genres = genres self.votes = votes self.rating = rating self.runtime = runtime self.plot = plot self.cover_url = cover_url def __cmp__(self,other): return (self.title < other.title) def __str__(self): strOut = "% | % | % | %" % (self.title,self.director,self.year,self.rating) return strOut def allData(self): strOut = "% | % | % | % | % | % | % | % | % | % | % | % | % | %" % (self.title,self.director,self.cast,self.producer,self.writer,self.country,self.language,self.year,self.genres,self.votes,self.rating,self.runtime,self.plot,self.cover_url) return strOut class MovieApp: def __init__(self,master,randomList,orderedList): randomList = randomList orderedList = orderedList ## Creamos el frame frame = Frame(master) frame.grid() #Insertamos los botones self.lo = Button(frame, text="Lista ordenada", fg="blue", command=self.alphaMovies) self.la = Button(frame, text="Lista aleatoria", fg="blue", command=self.betaMovies) #La imagen filename = "portada.jpg" urllib.urlretrieve(self.imagen,filename) img = Image.open(filename) portada = ImageTk.PhotoImage(img) #Creo el canvas que contendra la imagen imagen=Canvas(root, background='gray') imagen.create_image(130,35,image=logo) #Añado el texto en el Label txt = datos texto = Label(root, text=txt) #Cargo los botones, el label y wl cavas self.lo.grid(column=0,row=0,side=LEFT) self.la.grid(column=0,row=0,side=LEFT) texto.grid(column=0,row=0,side=CENTER) portada.grid(column=0,row=0,side=RIGHT) #Datos ordenados def alphaMovies(self): x = x + 1 datos = configure(orderedList[x]) imagen = configure(orderedList[x].self.cover_url) #Datos aleatorios def betaMovies(self): x = x + 1 datos = configure(randomList[x]) imagen = configure(randomList[x].self.cover_url) ################################# #función ordenar lista aleatoriamente def randomMovie(movieList): randomList = random.shuffle(movieList) return randomList ################################# #función ordenar lista def orderMovie(movieList): orderedList = movieList.sort() return orderedList ################################# #función parser def parser(archivo): peliculas = abrirarchivo(archivo) ml = [] for peli in range(len(peliculas)): campos = peliculas[peli].split("|") pelicula = [] for campo in campos: if campo.find("&&"): campo = campo.split("&&") pelicula.append(campo) p = Movie(pelicula[0],pelicula[1],pelicula[2],pelicula[3],pelicula[4],pelicula[5],pelicula[6],pelicula[7],pelicula[8],pelicula[9],pelicula[10],pelicula[11],pelicula[12],pelicula[13]) ml.append(p) return ml ################################# #Abrimos el archivo def abrirarchivo(db): file = open(db,"r") peliculas = file.readlines() file.close() return peliculas ################################# #Ejecutamos la aplicacion def main(): #Guardamos la matriz de peliculas en una lista movieList = parser("peliculas100.dat") #Creamos 2 listas una ordenada y otra aleatoria orderedList = orderMovie(movieList) randomList = randomMovie(movieList) #Ejecuto el objeto root = Tk() #Cargo la clase MovieApp tkinter = MovieApp(root,randomList,orderedList) root.mainloop() main()
bichomen