-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
59 lines (43 loc) · 1.32 KB
/
Copy pathmain.py
File metadata and controls
59 lines (43 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from tkinter import *
from matplotlib.figure import Figure
from matplotlib.backends.backend_tkagg import (FigureCanvasTkAgg, NavigationToolbar2Tk)
# plot function is created for
# plotting the graph in
# tkinter window..
def plot():
# the figure that will contain the plot
fig = Figure(figsize=(5, 5), dpi=100)
# list of squares
y = [i ** 2 for i in range(101)]
# adding the subplot
plot1 = fig.add_subplot(111)
# plotting the graph
plot1.plot(y)
# creating the Tkinter canvas
# containing the Matplotlib figure
canvas = FigureCanvasTkAgg(fig, master=window)
canvas.draw()
# placing the canvas on the Tkinter window
canvas.get_tk_widget().pack()
# creating the Matplotlib toolbar
toolbar = NavigationToolbar2Tk(canvas, window)
toolbar.update()
# placing the toolbar on the Tkinter window
canvas.get_tk_widget().pack()
# the main Tkinter window
window = Tk()
# setting the title
window.title('Plotting in Tkinter')
# dimensions of the main window
window.geometry("500x500")
# button that displays the plot
plot_button = Button(master=window,
command=plot,
height=2,
width=10,
text="Plot")
# place the button
# in main window
plot_button.pack()
# run the gui
window.mainloop()