早上好, 我正在将tkinter与matplotlib一起使用,但是我遇到了一个问题,我会写下来。
我尝试了许多解决方案,但没有任何效果,因此,如果您之前曾遇到过该问题,或者只是知道它可以帮助我解决此问题,请尝试。 这是我的代码:
let
这是输出:
import matplotlib
matplotlib.use('TkAgg')
from tkinter import *
import tkinter.simpledialog
import matplotlib.pyplot as plt
import datetime
from matplotlib.figure import Figure
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
root = Tk()
root.geometry('1000x600')
middle = Frame(root)
middle.pack()
payments = {'.':0}
m = datetime.datetime.now()
def digram1():
global m
purpose = list(payments.keys())
amounts = list(payments.values())
plt.plot((purpose),(amounts))
plt.xlabel('Purpose')
plt.ylabel('Amounts')
plt.title('Outgoings for the '+ str(m.month)+'th month\n'+str(datetime.date.today()))
plt.show
fig = Figure(figsize=(5,5),dpi = 100)
ex = fig.add_subplot(111)
canvas = FigureCanvasTkAgg(ex,master=root)
canvas.show()
canvas.get_tk_widget().pack(side =tk.top,fill=tk.Both, expand = True)
digram1m = Button(middle,text='1st digram',command=digram1, height = 5,width =15 , fg ='green')
digram1m.grid(row = 5 , column = 6 ,sticky=E)
root.mainloop()
我正在使用Jupyter笔记本5.4.0。 谢谢您的时间。.