我试图在图形界面中进行绘图,当我看到它看起来像是什么时,我想用按钮确定更改刻度(当我点击OK时,def changerechelle应该这样做)但它没有似乎工作......我不知道为什么。我是初学者,所以我不理解我在互联网上发现的一切。
这是我的错误:
UserWarning:找不到标记的对象。使用label =' ...'克瓦格 个别情节。 warnings.warn("未找到带标签的物品。" Tkinter回调中的例外
这是我的代码:
from numpy import *from matplotlib.pyplot import *
from matplotlib.lines import *
from cmath import *
from scipy import interpolate
from scipy.signal import butter, lfilter, freqz
import os
import imp
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
import tkinter as tk
import pylab as pl
temps=linspace(0,50)
marche=linspace(0,50)
figure(1)
plot(temps, marche)
xlabel('Temps [heure]')
ylabel('Marche [s/j]')
grid(True)
legend(loc=0)
xmini=tk.DoubleVar()
ymini=tk.DoubleVar()
xmaxi=tk.DoubleVar()
ymaxi=tk.DoubleVar()
fenetre = tk.Tk()
graph = FigureCanvasTkAgg(figure(1), master=fenetre)
canvas = graph.get_tk_widget()
canvas.grid(row=0, column=0)
xmini= tk.Entry(fenetre, width=4)
xmini.grid(row = 1, column = 2)
label_xmin = tk.Label(fenetre, text = "Coord de l'abscisse minimale")
label_xmin.grid(row = 1, column = 1)
ymini = tk.Entry(fenetre, width=4)
ymini.grid(row = 2, column = 2)
label_ymin = tk.Label(fenetre, text = "Coord de l'ordonnée minimale")
label_ymin.grid(row = 2, column = 1)
xmaxi = tk.Entry(fenetre, width=4)
xmaxi.grid(row = 3, column = 2)
label_xmax = tk.Label(fenetre, text = "Coord de l'abscisse maximale")
label_xmax.grid(row = 3, column = 1)
ymaxi = tk.Entry(fenetre, width=4)
ymaxi.grid(row = 4, column = 2)
label_ymax = tk.Label(fenetre, text = "Coord de l'ordonnée maximale")
label_ymax.grid(row = 4, column = 1)
def changerechelle() :
xmin = xmini.get()
xmax = xmaxi.get()
ymin = ymini.get()
ymax = ymaxi.get()
figure(1)
plot(temps, marche)
xlim(xmin,xmax)
ylim(ymin,ymax)
graph = FigureCanvasTkAgg(figure(1), master=fenetre)
canvas = graph.get_tk_widget()
canvas.grid(row=0, column=0)
bouton=tk.Button(fenetre, text="OK", command=changerechelle)
bouton.grid(row=2,column=3)
close(figure(1))
fenetre.mainloop()