python - For each plot a new frame -
i'm practicing tkinter , matplotlib , came across i'd learn how do. idea simple: each plot, new page (a new frame).
it's simulation of true scenario i'm dealing with. in example should enter number of plots supposed happen click on 'file' > 'open plot' , plotting begins. thing is... know how embed 1 graph 1 frame, i'd learn how embed multiple graphs in different frames, later on can create 'next' button goes next frame contains next plot.
the following code not developed , contains mistakes, hope informs idea:
from tkinter import * import matplotlib matplotlib.use('tkagg') matplotlib import pyplot plt matplotlib.backends.backend_tkagg import figurecanvastkagg, navigationtoolbar2tkagg x = [1,2,3] y = [1,2,3] numberofplots = none numberofplots = eval(input('number of plots: ')) class app(): global numberofplots def __init__(self): root = tk() root.geometry('640x400') menu_bar = menu(root) root.configure(menu = menu_bar) menu_file = menu(menu_bar) menu_bar.add_cascade(label='file',menu = menu_file) menu_file.add_command(label='open plots',command = openplots) root.mainloop() def openplots(): global numberofplots fig = plt.figure() in range(numberofplots): plt.plot(x,y) # numberofplots = number of frames created frame = frame(root) frame.pack() canvas = figurecanvastkagg(fig, frame) canvas.show() canvas.get_tk_widget().pack(fill='both', expand=true) toolbar = navigationtoolbar2tkagg(canvas, frame) toolbar.update() canvas._tkcanvas.pack(fill='both', expand=true) run = app()
Comments
Post a Comment