Creating a program that will place an image onto a canvas. I want to add an X-axis, and Y-axis scrollbar onto the canvas, but I am not sure how to.
I would normally use a Frame, but the program I'm working on is using tkinter.Toplevel instead of using a Frame.
#----- Imports ---------------------
import os
import os.path
import sys
import tkinter
tk = tkinter
from tkinter import font
#----- Set flag for JPEG support ---
noJPEG = False
try:
from PIL import Image
Pimg = Image
from PIL import ImageDraw
Pdraw = ImageDraw.Draw
from PIL import ImageTk
Pimgtk = ImageTk
except ImportError:
noJPEG = True
#
#------------------------------------
# Create an invisible global parent window to hold all children.
# Facilitates easy closing of all windows by a mouse click.
_root = tk.Tk()
_root.withdraw()
#
#------------------------------------
# A writeable window for holding an image.
#
class ImageView(tk.Canvas):
def __init__(self, image, title=''):
master = tk.Toplevel(_root)
master.protocol("WM_DELETE_WINDOW", self.close)
tk.Canvas.__init__(self, master,
width = 600, height = 500,
scrollregion=(0,0, image.getWidth(),
image.getHeight()))
# Define class fields
## Image properties
self.master.title(title)
self.pack()
master.resizable(0,0)
self.foreground = "black"
self.image = image
self.height = image.getHeight()
self.width = image.getWidth()
# for later
#self.customFont = font.Font(family="Helvetica", size=12)
## Actionable items
self.mouseX = None
self.mouseY = None
self.mouseFxn = None
self.bind("<Button-1>", self.onClick) #bind action to button1 click
self.tags = None
_root.update() #redraw global window