[英]Scrollbar not functioning on Tkinter Figure Canvas
I realize there are similar questions already posted, but I have attempted to follow each solution with no luck. 我意识到已经发布了类似的问题,但是我尝试遵循每种解决方案都没有运气。
I have a figure created using matplotlib that has a variable amount of subplots. 我有一个使用matplotlib创建的图,该图具有可变数量的子图。 This figure is large and so many of the subplots are not visible on the page. 该图很大,因此许多子图在页面上不可见。
I'm trying to add a scrollbar to allow the user to view the additional subplots. 我正在尝试添加一个滚动条,以允许用户查看其他子图。 The scrollbar appears just as I expected it to, but it does not function at all. 滚动条的显示与我预期的一样,但是它根本不起作用。
Below is a portion of the code for this page. 以下是此页面的部分代码。
class PageTwo(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
canvas = FigureCanvasTkAgg(f,self)
canvas.draw()
scroll=Scrollbar(self, orient = VERTICAL)
scroll.pack(side = RIGHT, fill=tk.BOTH)
canvas.get_tk_widget().config(yscrollcommand=scroll.set)
scroll.config(command=canvas.get_tk_widget().yview)
canvas.get_tk_widget().pack(side=tk.TOP,fill=tk.BOTH,expand = True)
Here is the result: 结果如下:
Try this one. 试试这个。 You probably didn't put scroolbar into canvas. 您可能没有将scroolbar放到画布中。
class PageTwo(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
canvas = FigureCanvasTkAgg(f,self)
canvas.draw()
scroll=Scrollbar(canvas, orient = VERTICAL)
scroll.pack(side = RIGHT, fill=tk.BOTH)
canvas.get_tk_widget().config(yscrollcommand=scroll.set)
scroll.config(command=canvas.get_tk_widget().yview)
canvas.get_tk_widget().pack(side=tk.TOP,fill=tk.BOTH,expand = True)
So I changed this. 所以我改变了这一点。 scroll=Scrollbar(self, orient = VERTICAL)
To this scroll=Scrollbar(canvas, orient = VERTICAL)
scroll=Scrollbar(self, orient = VERTICAL)
到这个scroll=Scrollbar(canvas, orient = VERTICAL)
I was able to fix the scrollbar by configuring the scroll region using the following: 我可以通过使用以下配置滚动区域来修复滚动条:
canvas.get_tk_widget().config(scrollregion=(0,0,1000,10000))
However, when I scroll now, the figure is cut off where the bottom of the page used to be (See Image): 但是,当我现在滚动时,该图被切掉了页面底部曾经所在的位置(参见图片):
I'm now trying to figure out how to extend the FigureCanvasTkAgg to be able to view all of the subplots. 我现在正在尝试弄清楚如何扩展FigureCanvasTkAgg以查看所有子图。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.