Tkinter problems

1. Where can I find a good tutorial or set of examples for
      embeding matplotlib in Tkinter ?
   2. Problem: I created a simple test with Tkinter. First I plot my
      graph on __init__ (it works ok). Then I want to clear graph and
      plot on the same canvas with different parameters. The thing is
      that plot shows up only when I resize my window. Any idea what
      could I be doing wrong ? I was trying draw method but it doasn't
      work...

Here is my code:

Thanks for your help. Gregor Skrt

#!/usr/bin/env python

import matplotlib
matplotlib.use('TkAgg')

from numpy import arange, sin, pi , cos
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg,
NavigationToolbar2TkAgg
from matplotlib.figure import Figure

from Tkinter import *
import sys

class App:
    def __init__(self,master):
        frame = Frame(master)
        frame.pack()
       
        self.button= Button(frame,text='Quit',fg="black",command=frame.quit)
        self.button.pack(side=LEFT)
       
        self.hi_there=Button(frame,text="Plot Inverse
sin",command=self.plotnew)
        self.hi_there.pack(side=LEFT)
       
        # place a graph somewhere here
        self.f = Figure(figsize=(5,4), dpi=100)
        self.a = self.f.add_subplot(111)
        self.t = arange(0.0,3.0,0.01)
        self.s = sin(2*pi*self.t)
        self.a.grid(True)
        self.a.set_xlabel("cas [s]")
        self.a.set_ylabel("amplituda")
        self.a.plot(self.t,self.s)
       
        self.canvas = FigureCanvasTkAgg(self.f, master=root)
        self.canvas.show()
        self.canvas.get_tk_widget().pack(side=TOP, fill=BOTH, expand=1)
       
    def plotnew(self):
        #get values from controller board, database
        #self.f.clf() # clear the figure
        self.t=arange(0.0,5.0,0.05)
        self.s1=sin(2*pi*self.t)
        self.s2=self.s1*-1
        self.a.plot(self.t,self.s1,self.t,self.s2)
       
root=Tk()
app=App(root)
root.mainloop()

matplotlibtest_class.py (1.19 KB)

Here are a few links for item #1 in your list. I'm not yet skilled enough
to quickly answer #2. In summary, information about Tkinter is scattered
about in various places:)--at least my take on it.

Here are two links to get you started:

http://www.astro.washington.edu/users/rowen/TkinterSummary.html

This page has quite a few links to resources on Tkinter:

http://wiki.python.org/moin/TkInter

There is a complete book on the subject by Grayson, that is
from 2000. All the examples were online the last time I checked (
some years ago). Also there are used book copies for about $60 US that
can be found from the wiki.python.org link.

I am planning to get back into Tkinter soon. I have developed a
time-series plotting package but have not touched it in almost two
years:( Thus I have to re-learn a few things because I wasn't an
expert when I had to move to other things--things that earned me
billable hours!

One final observation: I find GUI programming to be a challenge but a lot
of fun. However, it takes time, at least for me, to work out many of the
details. However, matplotlib is an excellent tool to put at the heart of
anything used to plot technical data. Almost all of my software development
from 1963 on has been in Fortran. Still working on getting my "mind wrapped"
around object-oriented software and Python:) Python is my platform of choice
for any GUI development that I do. I find it a fantastic language!!

Hope this helps your.

                         Delbert

···

On Monday 23 February 2009, Gregor Skrt wrote:

   1. Where can I find a good tutorial or set of examples for
      embeding matplotlib in Tkinter ?
   2. Problem: I created a simple test with Tkinter. First I plot my
      graph on __init__ (it works ok). Then I want to clear graph and
      plot on the same canvas with different parameters. The thing is
      that plot shows up only when I resize my window. Any idea what
      could I be doing wrong ? I was trying draw method but it doasn't
      work...

Here is my code:

Thanks for your help. Gregor Skrt

Hi,

Please change plotnew to:

      def plotnew(self):
                #self.f.clf() # clear the figure
                self.t=arange(0.0,5.0,0.05)
                self.s1=sin(2*pi*self.t)
                self.s2=self.s1*-1
                self.a.plot(self.t,self.s1,self.t,self.s2)
    self.canvas.show()

I added self.canvas.show()

This works for me.

Gregor Skrt-2 wrote:

···

   1. Where can I find a good tutorial or set of examples for
      embeding matplotlib in Tkinter ?
   2. Problem: I created a simple test with Tkinter. First I plot my
      graph on __init__ (it works ok). Then I want to clear graph and
      plot on the same canvas with different parameters. The thing is
      that plot shows up only when I resize my window. Any idea what
      could I be doing wrong ? I was trying draw method but it doasn't
      work...

Here is my code:

Thanks for your help. Gregor Skrt

#!/usr/bin/env python

import matplotlib
matplotlib.use('TkAgg')

from numpy import arange, sin, pi , cos
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg,
NavigationToolbar2TkAgg
from matplotlib.figure import Figure

from Tkinter import *
import sys

class App:
    def __init__(self,master):
        frame = Frame(master)
        frame.pack()
       
        self.button=
Button(frame,text='Quit',fg="black",command=frame.quit)
        self.button.pack(side=LEFT)
       
        self.hi_there=Button(frame,text="Plot Inverse
sin",command=self.plotnew)
        self.hi_there.pack(side=LEFT)
       
        # place a graph somewhere here
        self.f = Figure(figsize=(5,4), dpi=100)
        self.a = self.f.add_subplot(111)
        self.t = arange(0.0,3.0,0.01)
        self.s = sin(2*pi*self.t)
        self.a.grid(True)
        self.a.set_xlabel("cas [s]")
        self.a.set_ylabel("amplituda")
        self.a.plot(self.t,self.s)
       
        self.canvas = FigureCanvasTkAgg(self.f, master=root)
        self.canvas.show()
        self.canvas.get_tk_widget().pack(side=TOP, fill=BOTH, expand=1)
       
    def plotnew(self):
        #get values from controller board, database
        #self.f.clf() # clear the figure
        self.t=arange(0.0,5.0,0.05)
        self.s1=sin(2*pi*self.t)
        self.s2=self.s1*-1
        self.a.plot(self.t,self.s1,self.t,self.s2)
       
root=Tk()
app=App(root)
root.mainloop()

#!/usr/bin/env python

import matplotlib
matplotlib.use('TkAgg')

from numpy import arange, sin, pi , cos
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg,
NavigationToolbar2TkAgg
from matplotlib.figure import Figure

from Tkinter import *
import sys

class App:
  def __init__(self,master):
    frame = Frame(master)
    frame.pack()
    
    self.button= Button(frame,text='Quit',fg="black",command=frame.quit)
    self.button.pack(side=LEFT)
    
    self.hi_there=Button(frame,text="Plot Inverse sin",command=self.plotnew)
    self.hi_there.pack(side=LEFT)
    
    # place a graph somewhere here
    self.f = Figure(figsize=(5,4), dpi=100)
    self.a = self.f.add_subplot(111)
    self.t = arange(0.0,3.0,0.01)
    self.s = sin(2*pi*self.t)
    self.a.grid(True)
    self.a.set_xlabel("cas [s]")
    self.a.set_ylabel("amplituda")
    self.a.plot(self.t,self.s)
    
    self.canvas = FigureCanvasTkAgg(self.f, master=root)
    self.canvas.show()
    self.canvas.get_tk_widget().pack(side=TOP, fill=BOTH, expand=1)
    
  def plotnew(self):
    #self.f.clf() # clear the figure
    self.t=arange(0.0,5.0,0.05)
    self.s1=sin(2*pi*self.t)
    self.s2=self.s1*-1
    self.a.plot(self.t,self.s1,self.t,self.s2)
    
root=Tk()
app=App(root)
root.mainloop()
------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco,
CA
-OSBC tackles the biggest issue in open source: Open Sourcing the
Enterprise
-Strategies to boost innovation and cut costs with open source
participation
-Receive a $600 discount off the registration fee with the source code:
SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

--
View this message in context: http://www.nabble.com/Tkinter-problems-tp22164234p24318566.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

2009/2/23 Gregor Skrt <gregor.skrt@...287...>:

1. Where can I find a good tutorial or set of examples for
embeding matplotlib in Tkinter ?
2. Problem: I created a simple test with Tkinter. First I plot my
graph on __init__ (it works ok). Then I want to clear graph and
plot on the same canvas with different parameters. The thing is
that plot shows up only when I resize my window. Any idea what
could I be doing wrong ? I was trying draw method but it doasn't
work...

Have you seen the embedding_in_tk*.py examples at

http://matplotlib.sourceforge.net/examples/user_interfaces/index.html

JDH