How to insert python tkinter window into browser?

Good. The output of the python program is displayed in the Tkinter .. window, which opens separately. What I want to do is embed this window in the browser. Here is the code:

import numpy as np
import matplotlib
import matplotlib.cbook as cbook
import matplotlib.image as image
import matplotlib.pyplot as plt

datafile = cbook.get_sample_data('logo2.png', asfileobj=False)

print 'loading', datafile

im = image.imread(datafile)

im[:,:,-1] = 0.5  # set the alpha channel

fig = plt.figure()

ax = fig.add_subplot(111)

ax.plot(np.random.rand(20), '-o', ms=20, lw=2, alpha=0.7, mfc='orange')

ax.grid()

fig.figimage(im, 10, 10)

plt.show()

Note that all variables are input parameters specified from the browser form field. Please help !! :-)

+5
source share
1 answer

Based on Joe Kington's answer to a similar question, the mplh5canvas backend is perhaps what you are looking for. Adapt your sample code to work with it,

import numpy as np
import matplotlib
import mplh5canvas

matplotlib.use('module://mplh5canvas.backend_h5canvas')

import matplotlib.cbook as cbook
import matplotlib.image as image
import matplotlib.pyplot as plt


fig = plt.figure()

ax = fig.add_subplot(111)

ax.plot(np.random.rand(20), '-o', ms=20, lw=2, alpha=0.7, mfc='orange')

ax.grid()

plt.show(open_plot=True)

, , , . , , . Chrome, Safari Opera ( , ), , .

+5

All Articles