I am new to this site, and I am trying to create a simple image viewer in Python 2.7 using Tkinter, But when I try to load an image in it,it does not show anything!, I bet it is something embarassingly obvious, but I dont know what's wrong. I am using Windows XP. Here's my code:
from Tkinter import *
import tkFileDialog
from PIL import ImageTk, Image
root = Tk(className="Image viewer")
canvas_width = 800
canvas_height = 600
root.config(bg="white")
def openimage():
picfile = tkFileDialog.askopenfilename()
img = ImageTk.PhotoImage(file=picfile)
canvas.create_image(0,0, anchor=NW, image=img)
yscrollbar = Scrollbar(root)
yscrollbar.pack(side=RIGHT, fill=Y)
xscrollbar = Scrollbar(root, orient=HORIZONTAL)
xscrollbar.pack(side=BOTTOM, fill=X)
canvas = Canvas(root, width=canvas_width, height=canvas_height, yscrollcommand=yscrollbar.set, xscrollcommand=xscrollbar.set)
button = Button(root,text="Open",command=openimage)
button.pack(side=BOTTOM)
canvas.pack(side=TOP)
yscrollbar.config(command=canvas.yview)
xscrollbar.config(command=canvas.xview)
mainloop()
Update: It works when i remove the file browser, and give it the path to a file, but i want the file browser, and using a label works, but scroll bars dont work with it, and i want to be able to scroll the picture.