matplotlib 我在tkinter中得到'canvas object has no attribute get_tk_widget'错误

t1rydlwq  于 2023-11-22  发布在  其他
关注(0)|答案(1)|浏览(152)

当我在thinkter库中运行以下代码时,我从get_tk_widget()得到一个属性错误。我得到'canvas object has no attribute get_tk_widget'错误。我可以写什么来代替这段代码?

try:
        if canvas:
            canvas.get_tk_widget().grid_forget()

x

canvas = FigureCanvasTkAgg(fig, master=root)
        canvas_widget = canvas.get_tk_widget()
        canvas_widget.grid(row=8, columnspan=4, sticky="nsew")
scrollbar = tk.Scrollbar(root, orient="horizontal", command=canvas_widget.get_tk_widget().xview)
        scrollbar.grid(row=9, columnspan=4, sticky="ew")
        canvas_widget.get_tk_widget().configure(xscrollcommand=scrollbar.set)
canvas_widget.get_tk_widget().bind('<Configure>', on_canvas_configure)

的数据
GUI屏幕打开,但是这里的get_tk_widget给出了属性错误。

pieyvz9o

pieyvz9o1#

canvas_widgettkinter.Canvas widget的一个示例,所以它没有get_tk_widget()功能。
您需要将这些canvas_widget.get_tk_widget()更改为canvas_widget

...
scrollbar = tk.Scrollbar(root, orient="horizontal", command=canvas_widget.xview)
scrollbar.grid(row=9, columnspan=4, sticky="ew")
canvas_widget.configure(xscrollcommand=scrollbar.set)
...
canvas_widget.bind("<Configure>", on_canvas_configure)

字符串

相关问题