I wrote a few lines of code that should draw a circle where I can adjust its radius by using a slider. Unfortunately there must be some major mistakes in my code but as I am a beginner it is hard to find them. Can anyone give me some advise to make it work?
A tiny GUI has been set up using tkinter including a Tk.Scale and a canvas. The function drawCircle creates a Circle artist. The essential part is connecting the slider with the function changeRadius but thats where I don't know what to do. See my code below...
import sys
if sys.version_info[0] < 3:
import Tkinter as Tk
else:
import tkinter as Tk
from matplotlib.figure import Figure
from matplotlib import pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
class PlotCircle():
def __init__(self, master):
self.master = master
master.iconify
self.f_rad = 2 # initial value
self.frame = Tk.Frame(master)
self.frame.pack(side=Tk.TOP, fill=Tk.BOTH, expand=0)
self.radius_label = Tk.Label(self.frame, text='Radius: ')
self.radius_label.pack(side=Tk.LEFT)
self.scroll_radius = Tk.Scale(self.frame, from_=1.0, to=3.0, resolution=0.05,
orient=Tk.HORIZONTAL, command=lambda:self.changeRadius(self.circle))
self.scroll_radius.set(2.0)
self.scroll_radius.pack(side=Tk.LEFT)
self.image_frame = Tk.Frame(master)
self.image_frame.pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
self.fig = Figure()
self.ax = self.fig.add_subplot(111)
self.ax.set_aspect('equal')
self.canvas = FigureCanvasTkAgg(self.fig, self.image_frame)
self.canvas.get_tk_widget().pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
self.canvas._tkcanvas.pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
def drawCircle(self):
self.circle = plt.Circle((0.5, 0.5), self.f_rad*0.1, color='#F97306', fill=False)
self.ax.add_artist(self.circle)
self.fig.canvas.draw()
def changeRadius(self, circ):
self.f_rad = float(self.scroll_radius.get())
print(self.f_rad)
circ.set_radius(self.f_rad)
self.fig.canvas.draw()
root = Tk.Tk()
PlotCircle(root)
root.mainloop()
By executing this code I get the following error:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\p.schulmeyer\AppData\Local\Continuum\anaconda3\lib\tkinter__init__.py", line 1705, in call
return self.func(*args)
TypeError: lambda() takes 0 positional arguments but 1 was given
I also tried using lambda e: or not using lambda at all but nothing helped. I guess my mistake must be something more fundamental. I really appreciate any help. Thanks!
You need to do the following changes to make your script work.
Ensure that you call drawCircle in constructor, hence self.circle is set
command needs a function that can accept a param
def __init__(self, master):
...
self.scroll_radius = Tk.Scale(self.frame, from_=1.0, to=3.0, resolution=0.05,
orient=Tk.HORIZONTAL, command=lambda x:self.changeRadius(x))
...
self.drawCircle()
def changeRadius(self, new_radius):
self.circle.set_radius(float(new_radius)*0.1)
self.fig.canvas.draw()
Related
I am new to tkinter and python and trying to write a simple program that lets me overlay line charts on the same plot. The code I have written (some taken from the 'matplotlib' site) keeps placing all the charts underneath each other. Is there a simpler way to do this. I cant seem to take the canvas or widgets outside the 'for' loop without it messing something up,my code and test 'csv' files are below.Any help or guidance please as to what I need to change?
from tkinter import ttk
import tkinter
from tkinter import *
from matplotlib.backends.backend_tkagg import (
FigureCanvasTkAgg, NavigationToolbar2Tk)
# Implement the default Matplotlib key bindings.
from matplotlib.backend_bases import key_press_handler
from matplotlib.figure import Figure
import numpy as np
root = tkinter.Tk()
root.wm_title("Embedding in Tk")
current_list = ['Blue', 'Green', 'Yellow']
for item in current_list:
x, y = np.loadtxt(item + '_' + 'Test.csv', skiprows=1, usecols=[2, 3],
unpack=True, delimiter=',')
fig = Figure(figsize=(2, 3), dpi=100)
fig.add_subplot(111).plot(x, y)
canvas = FigureCanvasTkAgg(fig, master=root) # A tk.DrawingArea.
canvas.draw()
canvas.get_tk_widget().pack(side=tkinter.TOP, fill=tkinter.BOTH, expand=1)
toolbar = NavigationToolbar2Tk(canvas, root)
toolbar.update()
canvas.get_tk_widget().pack(side=tkinter.TOP, fill=tkinter.BOTH, expand=1)
def on_key_press(event):
print("you pressed {}".format(event.key))
key_press_handler(event, canvas, toolbar)
canvas.mpl_connect("key_press_event", on_key_press)
def _quit():
root.quit() # stops mainloop
root.destroy() # this is necessary on Windows to prevent
# Fatal Python Error: PyEval_RestoreThread: NULL tstate
button = tkinter.Button(master=root, text="Quit", command=_quit)
button.pack(side=tkinter.BOTTOM)
tkinter.mainloop()
# If you put root.destroy() here, it will cause an error if the window is
# closed with the window manager.
csv test files - Blue_Test.csv
Name1,Name2,Name3,Name4,Name5,Name6,Name7,Name8
1,100,19,100,Blue,2000,1.00E-19,1.00E-09
2,110,20,101,Blue,3000,5.00E-19,1.00E+00
3,120,21,102,Blue,4000,9.00E-19,2.00E+00
4,150,24,105,Blue,7000,2.10E-18,5.00E+00
5,160,25,106,Blue,8000,2.50E-18,6.00E+00
## csv test files - Green_Test.csv
Name1,Name2,Name3,Name4,Name5,Name6,Name7,Name8
1,100,19,2000,Green,2000,1.00E-19,1.00E-09
2,110,20,3001,Green,3000,5.00E-19,1.00E+00
3,120,21,4002,Green,4000,9.00E-19,2.00E+00
4,150,24,5005,Green,7000,2.10E-18,5.00E+00
5,160,25,6006,Green,8000,2.50E-18,6.00E+00
## csv test files - Yellow_Test.csv
Name1,Name2,Name3,Name4,Name5,Name6,Name7,Name8
1,100,19,11000,Yellow,2000,1.00E-19,1.00E-09
2,110,20,12001,Yellow,3000,5.00E-19,1.00E+00
3,120,21,13002,Yellow,4000,9.00E-19,2.00E+00
4,150,24,14005,Yellow,7000,2.10E-18,5.00E+00
5,160,25,15006,Yellow,8000,2.50000,5.000000
The problem lies in the for item in current_list: loop, in each iteration of the loop the code creates a new subplot and draws it on the canvas. Instead, you should create one subplot and plot each dataset on it. Then once the loop has completed, draw the populated subplot on the canvas. https://pydatascience.org/2017/11/24/plot-multiple-lines-in-one-chart-with-different-style-python-matplotlib/
import tkinter
import numpy as np
# Implement the default Matplotlib key bindings.
from matplotlib.backend_bases import key_press_handler
from matplotlib.backends.backend_tkagg import (
FigureCanvasTkAgg, NavigationToolbar2Tk)
from matplotlib.figure import Figure
root = tkinter.Tk()
root.wm_title("Embedding in Tk")
current_list = ['Blue', 'Green', 'Yellow']
fig = Figure(figsize=(2, 3), dpi=100)
ax = fig.add_subplot(111)
for item in current_list:
x, y = np.loadtxt(item + '_' + 'Test.csv', skiprows=1, usecols=[2, 3],
unpack=True, delimiter=',')
ax.plot(x, y, label=item)
fig.legend()
canvas = FigureCanvasTkAgg(fig, master=root) # A tk.DrawingArea.
canvas.draw()
canvas.get_tk_widget().pack(side=tkinter.TOP, fill=tkinter.BOTH, expand=1)
toolbar = NavigationToolbar2Tk(canvas, root)
toolbar.update()
canvas.get_tk_widget().pack(side=tkinter.TOP, fill=tkinter.BOTH, expand=1)
def on_key_press(event):
print("you pressed {}".format(event.key))
key_press_handler(event, canvas, toolbar)
canvas.mpl_connect("key_press_event", on_key_press)
def _quit():
root.quit() # stops mainloop
root.destroy() # this is necessary on Windows to prevent
# Fatal Python Error: PyEval_RestoreThread: NULL tstate
button = tkinter.Button(master=root, text="Quit", command=_quit)
button.pack(side=tkinter.BOTTOM)
tkinter.mainloop()
# If you put root.destroy() here, it will cause an error if the window is
# closed with the window manager.
I wrote a code that allows to click inside an entry widget and activate a function that returns the mouse coordinates if clicked on a figure. The problem is that I want to click somewhere else than the figure or entry widget to deactivate the function but I don't know how to do that.
What I tried so far is binding (with bind) a callback function that deactivates the select_marker function to master (what obviously makes no sense) or to a certain Frame (didn't help). I couldn't find any solution by browsing SO or the web.
import sys
if sys.version_info[0] < 3:
import Tkinter as Tk
else:
import tkinter as Tk
from matplotlib.figure import Figure
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
import numpy as np
class Application():
def __init__(self, master):
self.master = master
master.iconify
self.entry_frame = Tk.Frame(master)
self.entry_frame.pack(side=Tk.TOP, fill=Tk.BOTH, expand=0)
self.m1_label = Tk.Label(self.entry_frame, text='Mouse Coordinates: ')
self.m1_label.pack(side=Tk.LEFT)
self.m1_entry = Tk.Entry(self.entry_frame, width=10)
self.m1_entry.pack(side=Tk.LEFT)
self.m1_entry.bind('<Button-1>', lambda e:self.callback(1))
self.image_frame = Tk.Frame(master)
self.image_frame.pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
self.image_frame.bind('<Button-1>', lambda e:self.callback(0)) # something like this
self.fig = Figure()
self.ax = self.fig.add_subplot(111)
self.ax.set_aspect('equal')
self.canvas = FigureCanvasTkAgg(self.fig, self.image_frame)
self.canvas.get_tk_widget().pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
self.canvas._tkcanvas.pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
self.widget_active = 0
self.fig.canvas.mpl_connect('button_press_event', self.select_marker)
def callback(self, state):
self.widget_active = state
print(state)
def select_marker(self, event):
if self.widget_active == 1:
if event.button == 1:
x = np.round(event.xdata,2)
y = np.round(event.ydata,2)
print(x,y)
self.m1_entry.delete(0,'end')
self.m1_entry.insert(0,(str(x)+', '+str(y)))
else:
pass
if self.widget_active == 0:
pass
root = Tk.Tk()
Application(root)
root.mainloop()
I would really appreciate if someone knows a way to get a callback if clicked somewhere except the entry widget or the figure. Thanks a lot!
I'm attempting to add a .jpeg image to my GUI while it has several other widgets.
With my code, I can display the image in a separate Tkinter window when I use the following command:
#self.label = Label(image = self.img)
However, whenever I try to add the image to the original Tkinter window, I get the error seen below my code. The way I tried to add it to the original Tkinter window is:
#self.label = Label(frame, image = self.img)
Replicating the error
Oddly enough, when I try to replicate the error in a shorter version of the code (such as directly below), it works. HOWEVER! To replicate the error in the shortened code, you need to create a different error first. Example: Replace text = "Try" with text = "%s" %yikes (because there is no variable yikes it will give you an error). After you change the code back to the EXACT way it was before, it produces the error I've descried below (TclError: image "pyimage__" doesn't exit). At the very bottom, I've included the entire class since I'm having difficulty consistently replicating the issue. I'm using Python 2.7 and Canopy 1.5.5.
Shortened code:
import matplotlib.pyplot as plt
from Tkinter import *
from PIL import ImageTk, Image
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
import numpy as np
from tkFileDialog import askopenfilename, askdirectory
class App:
def __init__(self, master):
frame = Frame(master)
self.button_left = Button(frame,text="< Previous Event")
self.button_left.grid(row=1,column=0)
self.button_right = Button(frame,text="Next Event >")
self.button_right.grid(row=1,column=3)
#Creating text for the UI indicating the number of leakage events
w = Label(frame, text="Trying to Recreate error")
w.grid(row=1,column=2)
self.m = Canvas(frame,width=50,height=25)
self.text_id = self.m.create_text(25,12.5, text="Try")
self.m.grid(row=1,column=1)
self.path = "C:\Carbonite\EL_36604.02_231694\EL_36604.02_231694_2015-06-15 10.39.57.jpeg"
self.image = Image.open(self.path)
self.img = ImageTk.PhotoImage(self.image)
#self.label = Label(image = self.img)
self.label = Label(frame,image = self.img)
self.label.image = self.img
self.label.grid(row = 3, column = 0)
frame.grid(row=0,column=0)
root = Tk()
app = App(root)
root.mainloop()
Error I receive in my program when I use the commented out method:
TclError Traceback (most recent call last)
C:\Carbonite\Main_interface_file.py in <module>()
136
137 root = Tk()
--> 138 app = App(root)
139 root.mainloop()
140
C:\Carbonite\Main_interface_file.py in __init__(self, master)
72 self.img = ImageTk.PhotoImage(self.image)
73 #self.label = Label(image = self.img)
---> 74 self.label = Label(frame,image = self.img)
75 self.label.image = self.img
76 self.label.grid(row=3, column = 0)
C:\Users\U10596\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.5.3123.win-x86_64\lib\lib-tk\Tkinter.pyc in __init__(self, master, cnf, **kw)
2585
2586 """
-> 2587 Widget.__init__(self, master, 'label', cnf, kw)
2588
2589 class Listbox(Widget, XView, YView):
C:\Users\U10596\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.5.3123.win-x86_64\lib\lib-tk\Tkinter.pyc in __init__(self, master, widgetName, cnf, kw, extra)
2084 del cnf[k]
2085 self.tk.call(
-> 2086 (widgetName, self._w) + extra + self._options(cnf))
2087 for k, v in classes:
2088 k.configure(self, v)
TclError: image "pyimage8" doesn't exist
Almost entire Code:
import matplotlib.pyplot as plt
from Tkinter import *
from PIL import ImageTk, Image
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
import numpy as np
from images_to_list import images_to_list
from tkFileDialog import askopenfilename, askdirectory
#Creating a class that creates the UI
class App:
def __init__(self, master):
self.event_num = 1
# Create a container
frame = Frame(master)
# Create 2 buttons (changes between leakage events
self.button_left = Button(frame,text="< Previous Event",
command=self.decrease)
self.button_left.grid(row=1,column=0)
self.button_right = Button(frame,text="Next Event >",
command=self.increase)
self.button_right.grid(row=1,column=3)
#Creating text for the UI indicating the number of leakage events
w = Label(frame, text="/ %s " % len(tft))
w.grid(row=1,column=2)
#Display the number of the current event in the series
self.m = Canvas(frame,width=50,height=25)
self.text_id = self.m.create_text(25,12.5, text="%s" % (self.event_num+1))
self.m.grid(row=1,column=1)
#Creating the plot of voltage data
self.fig = Figure()
self.ax = self.fig.add_subplot(111)
self.fig.autofmt_xdate()
import matplotlib.dates as mdates
self.ax.fmt_xdata = mdates.DateFormatter('%Y-%m-%d')
self.line, = self.ax.plot(tft[self.event_num],tf1[self.event_num],'.')
self.line2, = self.ax.plot(tft[self.event_num],tf2[self.event_num],'.')
self.ax.set_ylim([0,3.5])
self.path = "C:\Carbonite\EL_36604.02_231694\EL_36604.02_231694_2015-06-15 10.39.57.jpeg"
self.image = Image.open(self.path)
self.img = ImageTk.PhotoImage(self.image)
#self.label = Label(image = self.img)
self.label = Label(frame,image = self.img)
self.label.image = self.img
self.label.grid(row=3, column = 0)
self.canvas = FigureCanvasTkAgg(self.fig,master=master)
self.canvas.show()
self.canvas.get_tk_widget().grid(row=1,column=0)
frame.grid(row=0,column=0)
#Creating a textbox to jump to event number
self.textbox = Entry(frame,width=5)
button1 = Button(frame, text='Go', command=self.letsgo) #Linking "Go" button with letsgo function to jump to event number
self.textbox.grid(row=2,column=1)
button1.grid(row=2,column=2)
#function letsgo allows the user to jump to any event in the series
def letsgo(self):
txt = self.textbox.get()
try:
self.event_num = int(txt)
except ValueError:
print "Opps! The number you enter needs to be an integer!"
self.line.set_xdata(tft[self.event_num])
self.line.set_ydata(tf1[self.event_num])
self.line2.set_xdata(tft[self.event_num])
self.line2.set_ydata(tf2[self.event_num])
self.ax.set_xlim([min(tft[self.event_num]),max(tft[self.event_num])])
self.canvas.draw()
self.m.itemconfig(self.text_id, text="%s" % (self.event_num+1))
#function decrease allows the user to use the decrease button
def decrease(self):
if self.event_num == 0: #if statement accounts for if the user tries to see the event previous to the first one
self.event_num = len(tft)-1
else:
self.event_num -= 1
self.line.set_xdata(tft[self.event_num])
self.line.set_ydata(tf1[self.event_num])
self.line2.set_xdata(tft[self.event_num])
self.line2.set_ydata(tf2[self.event_num])
self.ax.set_xlim([min(tft[self.event_num]),max(tft[self.event_num])])
self.canvas.draw()
self.m.itemconfig(self.text_id, text="%s" % (self.event_num+1))
#function increase allows the user to use the increase button
def increase(self):
if self.event_num == len(tft)-1: #if statement accounts for if the user tries to see the event after the last one.
self.event_num = 0
else:
self.event_num += 1
self.line.set_xdata(tft[self.event_num])
self.line.set_ydata(tf1[self.event_num])
self.line2.set_xdata(tft[self.event_num])
self.line2.set_ydata(tf2[self.event_num])
self.ax.set_xlim([min(tft[self.event_num]),max(tft[self.event_num])])
self.canvas.draw()
self.m.itemconfig(self.text_id, text="%s" % (self.event_num+1))
root = Tk()
app = App(root)
root.mainloop()
You need to grid the Frame. When I add
frame.grid()
at the bottom of your __init__ method it works fine. I don't get an error when I run the code you posted, though. It just doesn't display the label. I wonder if this is some platform-dependent behavior. I'm using python 2.7 on Yosemite 10.10.5.
EDIT: I've tried your extended example, and as expected, I don't see the behavior you. I can change the code back and forth. When it's incorrect, I get an error; when it's correct, it runs fine.
The behavior you describe must have something to do with Canopy. The way the python interpreter works, it will compile the script to byte codes every time it runs; it doesn't know anything about what the script used to says.
Can you try running the suspect script from the command line? Also, perhaps you should add the canopy tag to your question.
I don't use Canopy, so I don't think I can help you, but I'm leaving the answer here as background for someone who hopefully can.
Good luck.
I found the issue!!
I used askopenfilename() in the very beginning of my code, which opened an extra Tkinter window. As a result, there were two Tkinter windows open and confused the program.
By sending everything to the first Tk window that was created (and removing the second), it resolved the issue.
I am trying to plot a graph using Matplotlib in tkinter. Here the graph should plot all the values of 'a' in the range 0-24. My code is as follows
import math
import matplotlib
matplotlib.use("TkAgg")
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
from tkinter import *
def att_func(d=0, n=0, z=0):
# Getting User inputs from the UI
d = d_user.get()
n = n_user.get()
z = z_user.get()
a = (-9.87 * math.sin(2 * ((2 * math.pi * (d - 81)) / 365)) + n * z)
a_label.configure(text=a)
return (a)
#Plotting the graph
class App:
def __init__(self, master):
frame = tkinter.Frame(master)
self.nbutton_graph = tkinter.Button(frame, text="Show Graph", command=self.graph)
self.nbutton_graph.pack()
f = Figure(figsize=(5, 5), dpi=100)
ab = f.add_subplot(111)
self.line, = ab.plot(range(24))
self.canvas = FigureCanvasTkAgg(f, self)
self.canvas.show()
self.canvas.get_tk_widget().pack()
def graph(self):
day_elevation_hrs = []
for i in range(24):
day_elevation_hrs.append(att_func(i, 0, 0)[0])
self.canvas.draw()
return
root = tkinter.Tk()
app = App(root)
# User Inputs
d_user = IntVar()
n_user = DoubleVar()
z_user = DoubleVar()
nlabel_d = Label(text="Enter d").pack()
nEntry_d = Entry(root, textvariable=d_user).pack()
nlabel_n = Label(text="Enter n").pack()
nEntry_n = Entry(root, textvariable=n_user).pack()
nlabel_z = Label(text="Enter z").pack()
nEntry_z = Entry(root, textvariable=z_user).pack()
# Displaying results
nlabel_a = Label(text="a is").pack()
a_label = Label(root, text="")
a_label.pack()
root.mainloop()
Here I am able to calculate what i need. But when I am trying to plot the same, I am unable to. I tried as many modification I could. But seems to be in a stale mate. I am sure that I am going wrong somewhere. but can't figure out where.
when i try to plot the same graph with matplotlib, with out tkinter, it works. but when I try to do it in a UI with tkinter i am unable to.. Here is the code for plotting graph in matplotlib without tkinter.
import matplotlib.pylab as pl
day_elevation_hrs=[]
for i in range(24):
day_elevation_hrs.append(att_func(i, 0, 0)[0])
pl.title("Elevation of a in range i")
pl.plot(day_elevation_hrs)
Your code won't run as posted, but I can see two definite problems.
First, your App is a frame that contains a canvas, but you never add the frame to the root window. Because of that, your canvas will be invisible.
Add the following code after you create an instance of App:
app.pack(side="top", fill="both", expand=True)
Second, you are making a common mistake when defining the button to display the graph. The command attribute takes a reference to a function. However, you are calling the graph() function, and using the result as the value of the command attribute.
In other words, change this:
self.nbutton_graph = Tk.Button(self, text="Show Graph", command=self.graph())
to this:
self.nbutton_graph = Tk.Button(self, text="Show Graph", command=self.graph)
Notice the lack of () after self.graph. This could be the reason why you are seeing errors like 'App' object has no attribute 'line', since you are calling the graph function before you fully initialize all your variables.
This documentation shows that the second explicit parameter for FigureCanvasTkAgg.__init__ should be the master. (It's really a keyword parameter.)
So, have you tried changing that line to ...
self.canvas = FigureCanvasTkAgg(f, master=master)
I have written a small GUI program with Tkinter because I like the ability to queue updates to the mainloop for successive item updates in order to create an interative animation of changing circle colors that are induced by data changes.
( this is something I have found matplotib to not play nicely with, i.e. if I use patches and I want to update the color of the patch I have found that I have to add a new patch on top of the existing patch, which leaves color residue)
However, I would like to benefit from Matplotlib's Toolbar so that I can use the zoom and panning functionality.
I am experimenting on how to do this with a small test program for simplicity and have gotten matplotlib and tkinter in the same window... BUT the zoom doesnt work!
I have 2 weeks experience with Matplotlib and a couple days with Tkinter so please correct me on any inaccurate statements or add additional suggestions.
Here is the small program I have written for testing in which the matplotlib zoom doesn't work:
import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
from matplotlib.figure import Figure
import sys
from Tkinter import *
import matplotlib.backends.backend_tkagg as tkagg
class App:
def __init__(self, master):
self.frame = Frame(master, bg='#FFFFFF', height=1000, width=1000,
borderwidth=1, relief=RAISED)
self.frame.pack(expand=YES, fill=BOTH)
self.button = Button(
self.frame, text="QUIT", fg="red", command=self.frame.quit
)
self.button.pack(side=BOTTOM)
self.hi_there = Button(self.frame, text="Hello", command=self.say_hi)
self.hi_there.pack(side=BOTTOM)
###
# Creating a canvas for Tk items
self.tkcanvas = Canvas(self.frame, height=600, width=600)
self.tkcanvas.config(background='yellow')
self.tkcanvas.pack()
self.tkcanvas.create_rectangle(0,0,100,100,fill='blue')
# Hoping to utilize the mpl toolbar for zooming function by doing:
self.fig = Figure(figsize=(4,.5))
self.mplcanvas = FigureCanvasTkAgg(self.fig, master=self.frame)
self.mplcanvas.get_tk_widget().pack(side='bottom', fill='both')
self.mplcanvas._tkcanvas.pack(side='bottom', fill='both', expand=1)
#
self.mpltoolbar = NavigationToolbar2TkAgg( self.mplcanvas, master )
self.mpltoolbar.update()
self.mpltoolbar.pack()
###
def say_hi(self):
print "hi there, everyone!"
root = Tk()
app = App(root)
root.mainloop()
root.destroy()