简体   繁体   中英

why this code doesn't work? (python images and tkinter)

I've this code but it doesn't work, it runs but don't load the pictures when an optionMenu changes!

Principal Code:

def configuracion():
global imagen_local,imagen_visita, window,logos,a
window = Toplevel(app)
window.resizable(width=False,height=False)
window.iconbitmap(sources.get_path("images","ico"))
logos = {
    "Boston Celtics":sources.get_image("Boston Celtics","equipos"),
    "Charlotte Bobcats":sources.get_image("Charlotte Bobcats","equipos"),
    "Chicago Bulls":sources.get_image("Chicago Bulls","equipos"),
    "Cleveland Cavaliers":sources.get_image("Cleveland Cavaliers","equipos"),
    "Dallas Mavericks":sources.get_image("Dallas Mavericks","equipos"),
    "Detroit Pistons":sources.get_image("Detroit Pistons","equipos"),
    "Los Angeles Lakers":sources.get_image("Los Angeles Lakers","equipos"),
    "Miami Heat":sources.get_image("Miami Heat","equipos"),
    "Minnesota Timberwolves":sources.get_image("Minnesota Timberwolves","equipos"),
    "New Orleans Hornets":sources.get_image("New Orleans Hornets","equipos"),
    "New York Knicks":sources.get_image("New York Knicks","equipos"),
    "Toronto Raptors":sources.get_image("Toronto Raptors","equipos"),
    "Washington Wizards":sources.get_image("Washington Wizards","equipos"),
    "New Jersey Nets":sources.get_image("New Jersey Nets","equipos")
}
def ac_im(event):
    global imagen_local,imagen_visita,logos,a
    imagen_local = logos[equipo1.get()]
    imagen_visita = logos[equipo2.get()]
    return 0

equipos_list=["Boston Celtics","Charlotte Bobcats","Chicago Bulls","Cleveland Cavaliers","Dallas Mavericks","Detroit Pistons","Los Angeles Lakers","Miami Heat","Minnesota Timberwolves","New Orleans Hornets","New York Knicks","New Jersey Nets","Toronto Raptors","Washington Wizards"]

equipo1 = StringVar()
equipo2 = StringVar()

equipo1.set(equipos_list[0])
equipo2.set(equipos_list[-1])

list_equipo1 = OptionMenu(window, equipo1,*equipos_list,command=ac_im)
list_equipo2 = OptionMenu(window, equipo2,*equipos_list,command=ac_im)

list_equipo1.grid(row=1,column=0)
list_equipo2.grid(row=1,column=2)

###
imagen_local = sources.get_image(equipo1.get(),"equipos")
imagen_visita = sources.get_image(equipo2.get(),"equipos")

imagen_local_packed = Label(window,image=imagen_local)
imagen_visita_packed = Label(window,image=imagen_visita)
vs = Label(window,text="     Vs     ",font=("Consolas",30)).grid(row=0,column=1)

imagen_local_packed.grid(row=0,column=0)
imagen_visita_packed.grid(row=0,column=2)



window.protocol("WM_DELETE_WINDOW", retornar)
window.mainloop()
return 0

Auxiliar Code:

def get_image(img,Carpeta = "images"):
path = os.path.join(Folder[Carpeta],Files[img])
img = PhotoImage(file = path)
return img

The pictures exists and the path is fine!!! But, as I said, it does't work!!!

Thank you! Some pictures: Before https://dl.dropboxusercontent.com/u/15084304/2.png Later https://dl.dropboxusercontent.com/u/15084304/1.png

Kendall,

Have you tried moving the following lines up to be interpreted earlier in the script?

imagen_local = sources.get_image(equipo1.get(),"equipos")
imagen_visita = sources.get_image(equipo2.get(),"equipos")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM