Fairly new to Tkinter. I've looked in numerous posts about this issue, but none fixed it for me. I'm trying to create a simple GUI, in which I have a canvas which displays an image. The canvas is scrollable, but the scrollbars won't stretch to the size of the canvas.
Following is the relevant part of my code. there is no code here actually displaying the image, the image is given by an openFileDialog, but the scrollbars remain the same with the image.
from Tkinter import *
import Image
import ImageTk
import numpy as np
import tkFileDialog
import os as os
class DIP(Frame):
def __init__(self, parent):
Frame.__init__(self, parent)
self.parent = parent
self.initUI()
self.isOpenedYet = False
def initUI(self):
self.parent.title("Viewer")
self.pack(fill = BOTH, expand = 1)
menubar = Menu(self.parent)
self.parent.config(menu = menubar)
vsframe = Frame(self, width=500, height=500)
vsframe.grid(row = 1, column = 2, columnspan = 2, sticky = "nw")
hsframe = Frame(self, width=500, height=500)
hsframe.grid(row = 2, column = 1, rowspan = 2, sticky = "nw")
self.canv = Canvas(self, relief=SUNKEN)
self.canv.config(width=500, height=500)
self.canv.config(highlightthickness=0)
self.sbarV = Scrollbar(vsframe, orient=VERTICAL)
self.sbarH = Scrollbar(hsframe, orient=HORIZONTAL)
self.sbarV.config(command=self.canv.yview)
self.sbarH.config(command=self.canv.xview)
self.canv.config(yscrollcommand=self.sbarV.set)
self.canv.config(xscrollcommand=self.sbarH.set)
self.sbarV.pack(expand = YES, fill=BOTH)
self.sbarH.pack(expand = YES, fill=BOTH)
self.label2 = Label(self, border = 5)
self.label2.grid(row = 0, column = 1)
self.canv.grid(row = 1, column = 1, sticky = "nw")
#Open Image Menu
fileMenu = Menu(menubar)
fileMenu.add_command(label = "Open", command = self.onOpen)
menubar.add_cascade(label = "File", menu = fileMenu)
#menu for algorithms
basicMenu = Menu(menubar)
basicMenu.add_command(label = "Super Resolution-stub", command = self.SuperRes)
menubar.add_cascade(label = "Algorithms", menu = basicMenu)
What am I missing?