Hi, could anyone help me updating my pictures and texts. The first picture and text is okay but then the next just gets added in the same textarea instead of "refreshing the page" and adding the next "page" with a pic and text. I also get this error message.
screen.delete(0.0, END)
NameError: global name 'END' is not defined
Another question is would a tupple with the pictures and info about the picstures be better than a dictionary with the pictures, as i have it at the moment?
Thanks in advance.
# -*- coding: cp1252 -*-
#My encyclopedia.
#An interactive encyclopedia which shows
#pictures and information about them.
import Tkinter, ImageTk, Image
root = Tkinter.Tk()
root.title("Encyclopedia")
#Dictionary with pictures for encyclopedia
myImage = {
"mk1":ImageTk.PhotoImage(Image.open('img/Golf_Mk1.jpg')),
"mk2":ImageTk.PhotoImage(Image.open('img/Golf_Mk2.jpg'))
}
def main():
create_widgets()
root.mainloop()
def create_widgets():
""" create text area and buttons"""
global screen
global info
#Text area for pictures
screen = Tkinter.Text(root, width = 40, height = 13, bg = "Grey")
screen.pack(side = Tkinter.TOP, expand=Tkinter.YES, fill=Tkinter.BOTH)
screen.insert(0.0, '\n\n\t Welcome to the Golfs history\n\n')
#Text area for information about pictures
info = Tkinter.Text(root, width = 40, height = 8, bg = "White")
info.pack(side = Tkinter.TOP, expand=Tkinter.YES, fill=Tkinter.BOTH)
#Previous button
prev = Tkinter.Button(root, width = 20, text = "Previous", fg = "Blue" )
prev.pack(side = Tkinter.LEFT)
#Next buttton
nexst = Tkinter.Button(root, width = 20, text = "Next", fg = "Blue", command = encyclo )
nexst.pack(side = Tkinter.LEFT, fill=Tkinter.X)
#Cancel button
stop = Tkinter.Button(root, width = 20, text = "Cancel", fg = "Blue", command = root.destroy)
stop.pack(side = Tkinter.RIGHT, expand=Tkinter.YES)
def encyclo():
""" Where pictures and text about them get updated """
#Create picture heading
screen.insert(0.0, '\n\n\t Golf Mk1 (A1/Typ 17, 1974-1984)\n\n')
#Insert picture
screen.image_create('5.1', image=myImage['mk1'])
#insert information about the picture
info.insert(0.0, "In May, 1974 Volkswagen presented the first-generation\n"
"Golf as a modern front wheel drive long-range\n replacement of the Beetle.")
#Delete picture and heading
screen.delete(0.0, END)
#insert new heading
screen.insert(0.0, "Golf Mk2 (A2/Typ 19E, 1985-1992)\n\n")
#Insert new picture
screen.image_create('1.1', image=myImage['mk2'])
info.delete(0.0, END)
info.insert(0.0, "Mk2 that slightly grew in terms of wheelbase, exterior \n"
"and interior dimensions while retaining in somewhat more \n"
"rounded form the Mk1's overall look. In 1985, the first \n"
"Golfs with four-wheel drive (Golf Country) went on sale.")
main()