当前位置: 动力学知识库 > 问答 > 编程问答 >

matplotlib - Resizing a plot in Tkinter

问题描述:

I am fooling around making a small program for some personal use with Tkinter, and it will contain a plot which needs to be resized if the window is resized. This works if I make the window smaller, however, if I increase the window size the plot stays the same size after it has reached some size (although it nicely sticks to the middle of the frame it is in). I tried both pack and grid, but I don't understand why it will resize any bigger ... Currently I set to original image to 21 by 13 inches (but I would like to know what prevents/prohibits it from resizing in the first place.

this is my code (I know its a bit bulky..)

from Tkinter import *

import ttk

import misc

import matplotlib

matplotlib.use('TkAgg')

import matplotlib.pyplot as plt

from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg

from matplotlib.figure import Figure

root = Tk()

root.title("Plotting Customers Lines")

content = ttk.Frame(root, padding=(3,3,12,12))

plot = ttk.Frame(root, padding=(3,3,12,12))

toolbarframe = ttk.Frame(root)

subject = StringVar(content)

dropdown = ttk.Combobox(content, textvariable = subject, values = ['To', 'Do', 'Later'])

ok = ttk.Button(content, text='Plot Timeline')

f = plt.figure(figsize=(21,13))

a = f.add_subplot(111)

a.plot(range(100),range(100))

canvas = FigureCanvasTkAgg(f, plot)

canvas.show()

toolbar = NavigationToolbar2TkAgg(canvas, toolbarframe)

toolbar.update()

content.grid(column=1, row=0)

plot.grid(column=0,row=0)

toolbarframe.grid(column=0,row=1)

ok.grid(column=1, row=1)

dropdown.grid(column=1,row=0)

canvas.get_tk_widget().grid(column=0, row=0, sticky=(N,W,E,S))#pack(side=TOP, fill=BOTH, expand = True)#grid(column=0, row=0, sticky=(N,W,E,S))

root.columnconfigure(0, weight = 1)

root.columnconfigure(1, weight = 0)

root.rowconfigure(0, weight = 1)

root.rowconfigure(1, weight = 0)

plot.columnconfigure(0, weight = 1)

plot.rowconfigure(0, weight = 1)

root.mainloop()

分享给朋友:
您可能感兴趣的文章:
随机阅读: