Я пытаюсь разместить панель инструментов навигации в окне холста.Но при попытке запустить код появляется только панель инструментов.Линии, которые я попробовал, также включены ниже с #
.Как это можно исправить?
Код исполняемый.Значения первого окна были назначены, просто нажмите кнопку «Клик».
import numpy as np
import xlsxwriter
import tkinter as tk
from tkinter import *
import matplotlib
matplotlib.use('TkAgg')
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2Tk
from matplotlib.figure import Figure
window=Tk()
def open_window1():
y = 1/2
b = 1/4
result = []
u = []
v = []
t = []
p = [0,25,43.3013,50,43.3013,25,0,0,0,0,0,0]
a = []
pn = []
pn.append(0)
x = 0.0
for i in range(11):
z = x
t.append("%.1f" % z)
x = x + 0.1
m = 45594/100000
k = 18
c = 0.2865
u.append(0)
v.append(0)
a.append((p[0]-c*v[0]-k*u[0])/m)
dt = 0.1
a1 =(m/(b*dt*dt)+y*c/(b*dt))
a2 = (m/(b*dt)+(y/b-1)*c)
a3 = (((1/(2*b))-1)*m + dt*((y/(2*b))-1)*c)
kn = k + a1
for i in range(len(t)-1):
pn.append(np.around(p[i+1]+ a1*u[i] + a2*v[i] + a3*a[i], decimals=4))
u.append(np.around(pn[i+1]/kn, decimals=4))
v.append(np.around(y*(u[i+1]-u[i])/(b*dt) + (1-y/b)*v[i] + dt* (1-y/(2*b))*a[i], decimals=4))
a.append(np.around((u[i+1]-u[i])/(b*dt*dt) - v[i]/(b*dt)-(1/(2*b)-1)*a[i], decimals=4))
top = tk.Toplevel()
top.wm_geometry("1400x594")
top.title('Result table')
canvas = tk.Canvas(top,bg="white", width=1395, height=594)
canvas.grid(row=0,column=180)
#b1 = tk.Label(canvas, text="ti")
#b1.grid(row=3, column=0)
#b2 = tk.Label(canvas, text="Pi")
#b2.grid(row=3, column=200)
b1 = tk.Label(canvas, text="ti", font= "calibri 13", bg="white")
canvas.create_window(3,3, window=b1, anchor=tk.NW)
b2 = tk.Label(canvas, text="Pi", font= "calibri 13", bg="white")
canvas.create_window(150,3, window=b2, anchor=tk.NW)
b6 = tk.Label(canvas, text="Pni", font= "calibri 13", bg="white")
canvas.create_window(300,3, window=b6, anchor=tk.NW)
b3 = tk.Label(canvas, text="u''i", font= "calibri 13", bg="white")
canvas.create_window(450,3, window=b3, anchor=tk.NW)
b4 = tk.Label(canvas, text="u'i", font= "calibri 13", bg="white")
canvas.create_window(600,3, window=b4, anchor=tk.NW)
b5 = tk.Label(canvas, text="ui", font= "calibri 13", bg="white")
canvas.create_window(750,3, window=b5, anchor=tk.NW)
for i in range(1,len(t)):
b6 = tk.Label(canvas, text=t[i], font= "calibri 12", bg="white")
canvas.create_window(3,50*i, window=b6, anchor=tk.NW)
for i in range(1,len(t)):
b6 = tk.Label(canvas, text=p[i], font= "calibri 12", bg="white")
canvas.create_window(150,50*i, window=b6, anchor=tk.NW)
for i in range(1,len(t)):
b6 = tk.Label(canvas, text=pn[i], font= "calibri 12", bg="white")
canvas.create_window(300,50*i, window=b6, anchor=tk.NW)
for i in range(1,len(t)):
b6 = tk.Label(canvas, text=a[i], font= "calibri 12", bg="white")
canvas.create_window(450,50*i, window=b6, anchor=tk.NW)
for i in range(1,len(t)):
b6 = tk.Label(canvas, text=v[i], font= "calibri 12", bg="white")
canvas.create_window(600,50*i, window=b6, anchor=tk.NW)
for i in range(1,len(t)):
b6 = tk.Label(canvas, text=u[i], font= "calibri 12", bg="white")
canvas.create_window(750,50*i, window=b6, anchor=tk.NW)
f = Figure(figsize=(5,5), dpi=100)
q = f.add_subplot(111)
q.plot(t,a)
figure = FigureCanvasTkAgg(f, canvas)
figure.draw()
canvas.create_window(850, 3, window=figure.get_tk_widget(), anchor=tk.NW)
#toolbar= NavigationToolbar2Tk(figure, canvas)
#toolbar.update()
#canvas.create_window(850, 800, window=figure._tkcanvas, anchor=tk.NW)
b2=Button(window, text="Click", width=12, command=open_window1)
b2.grid(row=5,column=0)
window.title("Fill in the blanks")
window.geometry("300x150")
window.mainloop()