gpt4 book ai didi

Python/Tkinter : Can't use a button to update a graph?

转载 作者:太空宇宙 更新时间:2023-11-03 19:34:45 24 4
gpt4 key购买 nike

简化的问题:由于某种原因,当我点击“生成图”按钮时,图没有更新。

global f

master = Tk()

plotFrame = Frame(master)
plotFrame.pack(side=TOP)

f = Figure()

canvas = FigureCanvasTkAgg(f, plotFrame)
canvas.get_tk_widget().pack()
toolbar = NavigationToolbar2TkAgg(canvas,master)
toolbar.pack(side=BOTTOM)

def grph():
graph1 = f.add_subplot(111)
graph1.plot([1,2,3])

genButton = Button(master, text="Generate plots...", command=grph)
genButton.pack(side=LEFT,anchor=W)

master.mainloop()

最佳答案

添加这一行:

def grph():
graph1 = f.add_subplot(111)
graph1.plot([1,2,3])
canvas.draw()

关于Python/Tkinter : Can't use a button to update a graph?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4106546/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com