0

I want to create a window inside a window. The outer window is just plain and the inner window is a graph. The reason for it is that I would like to make a monitoring system with multiple graphs where nested windows would help.

Here is the code :

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import Tkinter

x = []
y = []

top = Tkinter.Tk()

top.title("Hello tkInter");
top.geometry("1000x1000")

fig=plt.figure()

rect = fig.patch
rect.set_facecolor('#31312e')

readFile = open('sampleCSV.csv','r')
sepFile = readFile.read().split('\n')
readFile.close()

for plotPair in sepFile:
    xAndY = plotPair.split(',')
    if xAndY[0] != '':
        x.append(int(xAndY[0]))
        y.append(int(xAndY[1]))

ax1 = fig.add_subplot(2,2,1, axisbg='grey')
ax1.plot(x, y, 'c', linewidth=3.3)
ax1.tick_params(axis='x', colors='c')
ax1.tick_params(axis='y', colors='c')
ax1.spines['bottom'].set_color('w')
ax1.spines['top'].set_color('w')
ax1.spines['left'].set_color('w')
ax1.spines['right'].set_color('w')
ax1.yaxis.label.set_color('c')
ax1.xaxis.label.set_color('c')
ax1.set_title('Matplotlib graph', color = 'c')
ax1.set_xlabel('x axis')
ax1.set_ylabel('y axis')

ax2 = fig.add_subplot(2,2,2, axisbg='grey')
ax2.plot(x, y, 'c', linewidth=3.3)
ax2.tick_params(axis='x', colors='c')
ax2.tick_params(axis='y', colors='c')
ax2.spines['bottom'].set_color('w')
ax2.spines['top'].set_color('w')
ax2.spines['left'].set_color('w')
ax2.spines['right'].set_color('w')
ax2.yaxis.label.set_color('c')
ax2.xaxis.label.set_color('c')
ax2.set_title('Matplotlib graph', color = 'c')
ax2.set_xlabel('x axis')
ax2.set_ylabel('y axis')

ax3 = fig.add_subplot(2,1,2, axisbg='grey')
ax3.plot(x, y, 'c', linewidth=3.3)
ax3.tick_params(axis='x', colors='c')
ax3.tick_params(axis='y', colors='c')
ax3.spines['bottom'].set_color('w')
ax3.spines['top'].set_color('w')
ax3.spines['left'].set_color('w')
ax3.spines['right'].set_color('w')
ax3.yaxis.label.set_color('c')
ax3.xaxis.label.set_color('c')
ax3.set_title('Matplotlib graph', color = 'c')
ax3.set_xlabel('x axis')
ax3.set_ylabel('y axis')

plt.show()

fig.pack()

top.mainloop()

I am not able to figure out a solution to this. Please HELP!

3
  • 1
    Possible duplicate of Window inside window Commented Oct 19, 2015 at 3:29
  • Thank you Steven. This will definitely help ! Commented Oct 19, 2015 at 14:58
  • I've updated the code on the aforementioned question if you'd like to check back on that. Commented Oct 20, 2015 at 9:10

1 Answer 1

1

Please read about good SO questions. Too much code, no error traceback, no question. However, I believe your problem is that matplotlib and tkinter are not compatible, at least not without lots of work. If plt.show() actually runs, I expect that since fig is a matlab.pyplot.figure() or Figure instance, and that class does not have a tkinter pack method, fig.pack() raises an AttributeError.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.