我想制作一个程序,它从用户那里获取一个整数并在 Tkinkter 窗口中输入尽可能多的条目。从这些条目中获取数据并根据它们制作图表。但是当我打开我的程序时,一切都很好,只有一个图表是错误的。它向我显示了一个没有任何数据的空图表,没有标题,也没有“标签名称”。这是我的代码。请帮忙。我正在使用 Python 2.7.5,PyDev for Eclipse
# -*- coding: utf-8 -*-
import matplotlib.pyplot as mp
import Tkinter as T, sys
def end():
sys.exit()
def check():
z = e.get()
try:
z = int(z)
e.config(bg = 'green')
e.after(1000, lambda: e.config(bg = 'white'))
x = []
y = []
global x1, y1
x1 = []
y1 = []
l2 = T.Label(main, text = 'X',bg = 'yellow')
l2.pack()
for i in range(0,z):
x.append(T.Entry(main, justify = 'center'))
x[i].pack()
x1.append(x[i].get())
l3 = T.Label(main, text = 'Y', bg = '#3366ff')
l3.pack()
for i in range(0,z):
y.append(T.Entry(main, justify = 'center'))
y[i].pack()
y1.append(y[i].get())
except:
e.config(bg = 'red')
e.after(1000, lambda: e.config(bg = 'white'))
return x1,y1
def graph():
mp.ion()
mp.plot(x1,y1)
mp.title('Wykres')
mp.xlabel('x')
mp.ylabel('y')
mp.draw()
#====================================================================#
y1 = []
x1 = []
z = 0
main = T.Tk()
main.title('GRAPH')
main.geometry('600x600')
main.config(bg = "#3366ff")
e = T.Entry(main,justify = 'center')
l = T.Label(main,text = 'Podaj liczbę parametrów N =',bg = '#3366ff')
b1 = T.Button(main, text = 'OK', command = check)
b2 = T.Button(main, text = 'Rysuj', command = graph)
b = T.Button(main,text = 'Zakończ', command = end)
l.pack()
e.pack()
b1.pack()
b2.pack()
b.pack()
main.mainloop()