Python Forum
[Tkinter] Fixate graphs on scrollable canvas
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Fixate graphs on scrollable canvas
#5
Thanks! I tried that and I also set the canvas attached to the frame. That did not work, so I tried to also create a new frame attached to the canvas and attached to canvas with graph to that new frame.
And it is still not working, I really don't understand why

import tkinter as tk
import numpy as np
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
class Example:
    def __init__(self, master):
        self.clicks = 0
        self.master = master
        self.frame= tk.Frame(master,width=600,height=400,background="green")
        self.canv = tk.Canvas(self.frame, width=600, height=400,background="blue",scrollregion=(0,0,2000,2000))
        button = tk.Button(master,text='click',command= lambda: self.select(master))
 
        self.scrollY = tk.Scrollbar(self.frame, orient=tk.VERTICAL,
                                    command=self.canv.yview)
        self.scrollX = tk.Scrollbar(self.frame, orient=tk.HORIZONTAL,
                                    command=self.canv.xview)
 
        self.canv['xscrollcommand'] = self.scrollX.set
        self.canv['yscrollcommand'] = self.scrollY.set
 
        self.frame.grid(row=0,column=0,rowspan=3)
        self.scrollY.grid(row=3, column=1, sticky=tk.N+tk.S)
        button.grid(row=2,column=0,padx=10,sticky=tk.NW)
        self.scrollX.grid(row=4, column=0, sticky=tk.E+tk.W)
        self.canv.grid(row=3, column=0)
        self.framesub = tk.Frame(self.canv)
        self.framesub.bind("<Configure>",self.canv.configure(scrollregion=self.canv.bbox("all"),width=200,height=200))
        
    def select(self,master):
        self.clicks +=1

        shape = np.random.randint(0,2,[5,5])
        lon = np.arange(5)
        lat = np.arange(5)
        fig = Figure(figsize=(4,4))
        ax = fig.add_subplot(111)
        c = ax.pcolor(lon,lat,shape)
        fig.colorbar(c,ax=ax,fraction=0.046,pad=0.04)
        canvas1= FigureCanvasTkAgg(fig,self.framesub)
        #framesub.grid(row=0,column=self.clicks)
        canvas1.get_tk_widget().grid(row=0,column=0)


if __name__ == "__main__":
    root=tk.Tk()
    Example(root)
    root.mainloop()
Reply


Messages In This Thread
Fixate graphs on scrollable canvas - by janema - Apr-12-2019, 07:38 AM
RE: Fixate graphs on scrollable canvas - by Larz60+ - Apr-12-2019, 08:22 AM
RE: Fixate graphs on scrollable canvas - by janema - Apr-12-2019, 08:47 AM
RE: Fixate graphs on scrollable canvas - by Larz60+ - Apr-12-2019, 10:32 AM
RE: Fixate graphs on scrollable canvas - by janema - Apr-12-2019, 02:13 PM
RE: Fixate graphs on scrollable canvas - by janema - Apr-12-2019, 03:19 PM
RE: Fixate graphs on scrollable canvas - by Larz60+ - Apr-12-2019, 03:57 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyQt] PyQt5 drawing on scrollable area HeinKurz 3 2,499 Mar-28-2023, 12:58 PM
Last Post: Axel_Erfurt
  [Tkinter] Scrollable buttons with an add/delete button Clich3 5 5,935 Jun-16-2022, 07:19 PM
Last Post: rob101
  [Tkinter] How to create scrollable frame mandiatutti 7 8,888 Aug-07-2021, 03:34 PM
Last Post: deanhystad
Question [Tkinter] Scrollable Treeview: change behavior of Prior/Next keys? RockDoctor 2 4,660 Apr-10-2021, 05:40 PM
Last Post: RockDoctor
  Scrollable big image in a window (TKinter) Prospekteur 3 6,092 Sep-14-2020, 03:06 AM
Last Post: Larz60+
  [Tkinter] Resizing image inside Canvas (with Canvas' resize) Gupi 2 26,675 Jun-04-2019, 05:05 AM
Last Post: Gupi
  [Tkinter] ListBox not contained or scrollable kellykimble 6 7,497 Apr-05-2018, 11:59 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020