Hi im working on an encyclopedia. The problem im having is the following:
in next
print car_num, len (car_list)
NameError: global name 'car_list' is not defined
Line 62
I might also add that before i moved car_list into a separate script/module, everything worked fine. The idea is basically to have a very long list of information that one could page through but i would like to keep it separate from the actual code for possible future expansion.Thanks in advance.
# My encyclopedia.
# An interactive encyclopedia which shows
# pictures and information about them.
import Tkinter as tk
from PIL import ImageTk, Image
from car_list import *
root = tk.Tk()
root.title("Encyclopedia")
class Car(object):
"""this class creates a record structure"""
def __init__(self, title, info, image):
self.title = title
self.info = info
self.image = image
def main():
global car_num
car_num = 0
create_widgets()
root.mainloop()
def create_widgets():
""" create text area and buttons"""
global screen
global info
# text area for pictures
screen = tk.Text(root, width=40, height=13, bg="Grey")
screen.pack(side='top', expand='yes', fill='both')
screen.insert(0.0, '\n\n\t Welcome to the Golfs history\n\n')
# text area for information about pictures
info = tk.Text(root, width=40, height=8, bg="White")
info.pack(side='top', expand='yes', fill='both')
# previous button
prev = tk.Button(root, width=20, text="Previous", fg="Blue",
command=previous)
prev.pack(side='left')
# next buttton
nexst = tk.Button(root, width=20, text="Next", fg="Blue",
command=next)
nexst.pack(side='left', fill='x')
# quit button
quit = tk.Button(root, width=20, text="Quit", fg="Blue",
command=root.destroy)
quit.pack(side='right', expand='yes')
def next():
global car_num
global car_list
print car_num, len (car_list)
show(car_num)
#increment to next car number
if car_num < len(car_list)- 1:
car_num += 1
def previous():
global car_num
# decrement to previous car number
if car_num > 0:
car_num -= 1
show(car_num)
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
screen.image_create('2.0', image=car_list[car_num].image)
# insert information about the picture
info.insert('1.0', car_list[car_num].info)
main()