1

I am trying to write a simple program that reads the values of three different widgets and plots a graph of a function depending on what the input values are. I run into the following problems:

1) On the button press I get the error "App_Window instance has no attribute 'refreshFigure'"

2)On exiting ipython (I use ipython-listener in conjunction with a gedit plugin) I get the error "Exception RuntimeError: 'main thread is not in main loop' in del of

I've based this mostly on this thread - Interactive plot based on Tkinter and matplotlib and this thread - How do I refresh a matplotlib plot in a Tkinter window?

#!/usr/bin/python
from Tkinter import Tk, Frame
from Tkinter import *
import Tkinter
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
#this bit I added just because the NVC13 module is in another directory
import sys
for i in range(len(sys.path)):
    if sys.path[i]!='/home/captain-pants/NV_centri':
        if i==len(sys.path)-1:
            sys.path.append('/home/captain-pants/NV_centri')
        continue        
    else:
        break

import multiprocessing as mp 
import numpy as np
import matplotlib.pyplot as plt
#This module contains all the code necessary to return a list of values that depend on the input parameters
import NVC13_1lev_advanced_ex_nocoh as C13
from matplotlib.figure import Figure

#this function takes a list of parameters and returns a list of values dependant on those parameters.
def plotfunc(c13,Eg,Bz):
    Epam=[]
    nv = C13.NVC13(c13,[2580,1423],[Eg,Eg],0,0,Bz,0)
    evals = nv.intH()
    for i in range(len(evals[0])):
        Epam.append(np.real_if_close(evals[0][i]))
    return Epam

class App_Window:
    def __init__(self, parent):
        frame = Tkinter.Frame(parent)
        self.Egdata=DoubleVar()
        self.c13input=IntVar()
        self.Bzdata=DoubleVar()
        parent.title("Simple")
        Tkinter.Button(text='lulz',command=self.main1).grid(row=3,column=0)
        Tkinter.Label(textvariable=self.Egdata).grid(row=5,column=0)
        self.c13 = Tkinter.Entry(textvariable=self.c13input)
        self.Eg = Tkinter.Scale(orient='horizontal')
        self.Bz = Tkinter.Scale(orient='horizontal')
        self.c13.grid(row=6,column=0)
        self.Bz.grid(row=5,column=0)
        self.Eg.grid(row=4,column=0)
        Fig = Figure()
        FigSubPlot = Fig.add_subplot(111)
        self.line, = FigSubPlot.plot(range(10),'bo')
        x=[]
        y=[]
        self.canvas = FigureCanvasTkAgg(Fig, master=parent)
        self.canvas.show()
        self.canvas.get_tk_widget().grid(row=0,column=0,columnspan=2)
        frame.grid(row=0,column=0)
    def refreshFigure(self,y):
        x=np.arange(len(y))
        self.line.set_xdata(x)
        self.line.set_ydata(y)
        self.canvas.draw()
    def main1(self):
        self.c13input=int(self.c13.get())
        self.Egdata=self.Eg.get()
        self.Bzdata=self.Bz.get()
        values = plotfunc(self.c13input,self.Egdata,self.Bzdata)
            #Just to see whether I actually get the right thing in the input.
        print self.c13input
        self.refreshFigure(values)

root = Tkinter.Tk()
app = App_Window(root)
root.mainloop()
3
  • Could you post the whole error message with files and lines, everything? Commented Mar 4, 2014 at 15:18
  • I don't think the code you posted can possibly give the error you say it does, because App_Window clearly has a refreshFigure method. Are you certain this is the actual code that gives you the "App_Window instance has no attribute 'refreshFigure'" error? Commented Mar 4, 2014 at 18:52
  • Naming variables with capital letters is confusing; the typical naming convention is to make class names start with capital letters, while variables have lower-case letters. Commented Jan 14, 2017 at 19:24

0

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.