I'm trying to build a dashboard.
I want to keep the scrollbar just for the canvas area, but, on the contrary, it just stick to other frame.
The code I have written is this
# python dashboard
import tkinter as tk
from tkinter import *
class AutoScrollbar(Scrollbar):
def set(self, lo, hi):
if float(lo) <= 0.0 and float(hi) >= 1.0:
self.tk.call("grid", "remove", self)
else:
self.grid()
Scrollbar.set(self, lo, hi)
def pack(self, **kw):
raise TclError("cannot use pack with this widget")
def place(self, **kw):
raise TclError("cannot use place with this widget")
class Dashboard():
def __init__(self, root):
self.root=root
root.title("Dashboard View")
vsb = AutoScrollbar(root)
vsb.grid(row=0, column=1, sticky=N+S)
hsb = AutoScrollbar(root, orient=HORIZONTAL)
hsb.grid(row=1, column=0, sticky=E+W)
self.canvas=tk.Canvas(root,yscrollcommand=vsb.set,
xscrollcommand=hsb.set,background='blue')
vsb.config(command=self.canvas.yview)
hsb.config(command=self.canvas.xview)
root.grid_rowconfigure(0, weight=1)
root.grid_columnconfigure(0, weight=1)
self.canvas.grid(row=0,column=3)
frame = Frame(self.root, bd=2, relief=SUNKEN)
frame.grid(row=0,column=0, sticky="nw")
Button1=Button(frame,text="Status").grid(row = 0,column = 0, sticky = "we")
Button2=Button(frame,text="Processes").grid(row = 0,column = 1, sticky = "we")
Button3=Button(frame,text="Links").grid(row = 1,column = 0, sticky = "we")
Button4=Button(frame,text="Traffic").grid(row = 1,column = 1, sticky = "we")
Button5=Button(frame,text="App Version").grid(row = 2,column = 0, sticky = "we")
Button5=Button(frame,text="Archive/Purge").grid(row = 2,column = 1, sticky = "we")
fhandle = open("dashboard_content.txt")
lines = fhandle.read()
fhandle.close()
text1=self.canvas.create_text(400, 400, fill="white")
self.canvas.itemconfig(text1, text=lines)
frame.update_idletasks()
self.canvas.config(scrollregion=self.canvas.bbox("all"))
if __name__== '__main__':
root=tk.Tk()
board=Dashboard(root)
root.mainloop()
How can I get the scrollbar just for the Canvas window, "to the blue background"?