0

I meant something like this:

I changed the car_list file to make each Car instance's image attribute as a string of the image filename. Like so:

# ...
title = "Golf Mk1 (A1/Typ 17, 1974-1984)"
info = """\
In May, 1974 Volkswagen presented the first-generation
Golf as a modern front wheel drive long-range replacement
of the Beetle.
"""
image = 'Golf_Mk1.jpg'  # just the image filename
# create the class instance and append to the list
car_list.append(Car(title, info, image))
# ...

This means that you can remove all the imports for tk and PIL at the top of your car_list script, and also delete the root = tk.Tk() part.

Then, in the main file, I changed the show function so that it creates a Tk image of the filename upon showing it. Like this:

def show(car_num):
    global car_list
    global screen
    global info    
    
    # delete any previous picture, title and info
    screen.delete(0.0, 'end')
    info.delete(0.0, 'end')
    # create picture heading
    s = car_list[car_num].title + '\n\n'
    screen.insert('1.0', s)

    # insert picture
    img = ImageTk.PhotoImage(file=car_list[car_num].image)  # make image upon showing
    screen.image_create('2.0', image=img)  # changed to use the newly created image

    # insert information about the picture
    info.insert('1.0', car_list[car_num].info)
# ...

I'm also re-attaching this modified version so that you can see the changes better.

0

This thread makes my head hurt. Do you need to store all the info about the cars in a python module? What about a csv? Also, if you're going to call a class in a module, that class has to be part of the module if you're not doing it like this:

import module
x = module.theclass(args)

Also am I crazy, because I thought that python was not super keen on global variables. Most people will try to avoid these. Then you could have something like this: car_list = get_car_list() Your function pulls from a file with all the info in it. More compatible and always available.

That's how I would do it.

0

That was my initial thought (and moving in that direction), however, im still not sure how to implement it practically.

0

Hi there, im trying your ideas at the moment but i get no pics, everything else works fine.
My idea was similar but i did not convert to a string.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.