开发者

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

开发者 https://www.devze.com 2023-01-24 04:08 出处:网络
Simplified question: For some reason the plot isn\'t updating when I hit my generate plots button. global f

Simplified question: For some reason the plot isn't updating when I hit my generate plots button.

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)开发者_Go百科
    graph1.plot([1,2,3])

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

master.mainloop()


Add this line:

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

精彩评论

暂无评论...
验证码 换一张
取 消