Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #8943 > unrolled thread

trouble creating tooltips using Wx in Tk canvas

Started byRavikanth <vvnrk.vanapalli@gmail.com>
First post2011-07-06 08:12 -0700
Last post2011-07-06 21:04 -0400
Articles 4 — 3 participants

Back to article view | Back to comp.lang.python


Contents

  trouble creating tooltips using Wx in Tk canvas Ravikanth <vvnrk.vanapalli@gmail.com> - 2011-07-06 08:12 -0700
    Re: trouble creating tooltips using Wx in Tk canvas Ian Kelly <ian.g.kelly@gmail.com> - 2011-07-06 12:32 -0600
      Re: trouble creating tooltips using Wx in Tk canvas Ravikanth <vvnrk.vanapalli@gmail.com> - 2011-07-06 12:35 -0700
        Re: trouble creating tooltips using Wx in Tk canvas Kevin Walzer <kw@codebykevin.com> - 2011-07-06 21:04 -0400

#8943 — trouble creating tooltips using Wx in Tk canvas

FromRavikanth <vvnrk.vanapalli@gmail.com>
Date2011-07-06 08:12 -0700
Subjecttrouble creating tooltips using Wx in Tk canvas
Message-ID<e24f3835-8ff5-4163-a797-d8ec11f0327b@r2g2000vbj.googlegroups.com>
Hi all,
Hi all,

I am having a trouble creating tooltips. I am trying to embed a
matplotlib graph inside  a TkInter canvas. After some search over the
net, I found out a way to create tooltips using the WXbackend.
But when I embed my matplotlib figure inside a Tk and  the tooltips
are not getting displayed.
The error I am getting is below.

Traceback (most recent call last):
  File "U:\graphing_tool\plotinsideTkInter\plotInTk.py", line 12, in
<module>
    tooltip = wx.ToolTip(tip='tip with a long %s line and a newline\n'
% (' '*100)) # needs to be added to getover the bug with tooltip.
  File "C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\_misc.py",
line 771, in __init__
    _misc_.ToolTip_swiginit(self,_misc_.new_ToolTip(*args, **kwargs))
PyNoAppError: The wx.App object must be created first!

I am not able to figure out the reason. I am trying to use IDLE for
running the script using python 2.7. I tried running from commandline
as well but still i face the same error. Following is the piece of
code I have used.
I created a simple 'sin' wave using matplotlib. and a  button. Added
them to a TkFrame.
and then binded the code using

self.f.canvas.mpl_connect('motion_notify_event',_onMotion)

to '_onMotion' function, where I am printing the toooltip.

Can somebody please help me solving the issue.

Code I have used is below.

#!/usr/apps/Python/bin/python
import matplotlib, sys
matplotlib.use('WXAgg')
matplotlib.interactive(False)
import numpy as np
from numpy import arange, sin, pi
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg,
NavigationToolbar2TkAgg
from matplotlib.figure import Figure
import wx
import Tkinter
tooltip = wx.ToolTip(tip='tip with a long %s line and a newline\n' %
(' '*100))
 # needs to be added to getover the bug with tooltip.

def alt():
    print 'My Button'

def _onMotion(event):
    print "Xvalue:",event.xdata," Yvalue:",event.ydata
    tip= "Xvalue:{0}, Yvalue: {1}".format(event.xdata,event.ydata)
    tooltip.SetTip(tip)
    tooltip.Enable(True)

class  myClass(Tkinter.Tk):
    def __init__(self,parent):
        Tkinter.Tk.__init__(self,parent)
        #global _onMotion
        self.parent=parent

        self.buildFigure()

    def buildFigure(self):

        self.f=plt.figure()
        self.f = plt.figure(figsize=(5,4))
        self.a = self.f.add_subplot(111)
        self.t =
np.array([0.01,0.02,0.03,0.04,0.05,0.07,0.09,1.7,1.9,2.3,2.5,2.7,2.9])
        self.s = sin(2*pi*self.t)
        self.a.plot(self.t,self.s)


        self.dataPlot = FigureCanvasTkAgg(self.f, master=self)
        self.f.canvas.mpl_connect('motion_notify_event',_onMotion)
        self.dataPlot.get_tk_widget().pack(side='top', fill='both')
        self.toolbar = NavigationToolbar2TkAgg( self.dataPlot, self )
        self.toolbar.update()
        self.toolbar.pack()


        self.btn=Tkinter.Button(self, text='btton',command=alt)
        self.btn.pack(ipadx=250)

    def alt (self):
        print 9

if __name__ == "__main__":
    app = myClass(None)
    app.title('Embedding in Tk')
    app.mainloop()

[toc] | [next] | [standalone]


#8969

FromIan Kelly <ian.g.kelly@gmail.com>
Date2011-07-06 12:32 -0600
Message-ID<mailman.713.1309977210.1164.python-list@python.org>
In reply to#8943
On Wed, Jul 6, 2011 at 9:12 AM, Ravikanth <vvnrk.vanapalli@gmail.com> wrote:
> Hi all,
> Hi all,
>
> I am having a trouble creating tooltips. I am trying to embed a
> matplotlib graph inside  a TkInter canvas. After some search over the
> net, I found out a way to create tooltips using the WXbackend.
> But when I embed my matplotlib figure inside a Tk and  the tooltips
> are not getting displayed.

That's pretty much what I would expect, since wxPython and Tkinter are
completely different GUI libraries.  Trying to use them together is a
bit like trying to call a .NET function from Java -- maybe possible,
but it's going to take a lot of work.

> The error I am getting is below.
>
> Traceback (most recent call last):
>  File "U:\graphing_tool\plotinsideTkInter\plotInTk.py", line 12, in
> <module>
>    tooltip = wx.ToolTip(tip='tip with a long %s line and a newline\n'
> % (' '*100)) # needs to be added to getover the bug with tooltip.
>  File "C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\_misc.py",
> line 771, in __init__
>    _misc_.ToolTip_swiginit(self,_misc_.new_ToolTip(*args, **kwargs))
> PyNoAppError: The wx.App object must be created first!
>
> I am not able to figure out the reason.

As it says, you haven't created the wx.App object necessary for pretty
much all wxPython code.  You could create one, but your tooltip still
would not work correctly because you would be running the Tkinter
event loop rather than the wxPython event loop.  If you want to use
the wxToolTip widget, then you should write your program to use
wxPython only.  Alternatively, googling for "tkinter tooltip" turns up
a couple of recipes; you could try one of those.

Cheers,
Ian

[toc] | [prev] | [next] | [standalone]


#8977

FromRavikanth <vvnrk.vanapalli@gmail.com>
Date2011-07-06 12:35 -0700
Message-ID<93c9fa3a-5520-478a-9326-89d2229c3194@ct4g2000vbb.googlegroups.com>
In reply to#8969
On Jul 6, 1:32 pm, Ian Kelly <ian.g.ke...@gmail.com> wrote:
> On Wed, Jul 6, 2011 at 9:12 AM, Ravikanth <vvnrk.vanapa...@gmail.com> wrote:
> > Hi all,
> > Hi all,
>
> > I am having a trouble creating tooltips. I am trying to embed a
> > matplotlib graph inside  a TkInter canvas. After some search over the
> > net, I found out a way to create tooltips using the WXbackend.
> > But when I embed my matplotlib figure inside a Tk and  the tooltips
> > are not getting displayed.
>
> That's pretty much what I would expect, since wxPython and Tkinter are
> completely different GUI libraries.  Trying to use them together is a
> bit like trying to call a .NET function from Java -- maybe possible,
> but it's going to take a lot of work.
>
> > The error I am getting is below.
>
> > Traceback (most recent call last):
> >  File "U:\graphing_tool\plotinsideTkInter\plotInTk.py", line 12, in
> > <module>
> >    tooltip = wx.ToolTip(tip='tip with a long %s line and a newline\n'
> > % (' '*100)) # needs to be added to getover the bug with tooltip.
> >  File "C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\_misc.py",
> > line 771, in __init__
> >    _misc_.ToolTip_swiginit(self,_misc_.new_ToolTip(*args, **kwargs))
> > PyNoAppError: The wx.App object must be created first!
>
> > I am not able to figure out the reason.
>
> As it says, you haven't created the wx.App object necessary for pretty
> much all wxPython code.  You could create one, but your tooltip still
> would not work correctly because you would be running the Tkinter
> event loop rather than the wxPython event loop.  If you want to use
> the wxToolTip widget, then you should write your program to use
> wxPython only.  Alternatively, googling for "tkinter tooltip" turns up
> a couple of recipes; you could try one of those.
>
> Cheers,
> Ian

Thank you Ian for your insights to me on this.
I will migrate to wxPython to achieve the functionality.

[toc] | [prev] | [next] | [standalone]


#9005

FromKevin Walzer <kw@codebykevin.com>
Date2011-07-06 21:04 -0400
Message-ID<8709b$4e150668$4275d90a$21028@FUSE.NET>
In reply to#8977
On 7/6/11 3:35 PM, Ravikanth wrote:

>> As it says, you haven't created the wx.App object necessary for pretty
>> much all wxPython code.  You could create one, but your tooltip still
>> would not work correctly because you would be running the Tkinter
>> event loop rather than the wxPython event loop.  If you want to use
>> the wxToolTip widget, then you should write your program to use
>> wxPython only.  Alternatively, googling for "tkinter tooltip" turns up
>> a couple of recipes; you could try one of those.
>>
>> Cheers,
>> Ian
>
> Thank you Ian for your insights to me on this.
> I will migrate to wxPython to achieve the functionality.

Tooltips are trivial to create in Tkinter:

http://tkinter.unpythonic.net/wiki/ToolTip

--Kevin

-- 
Kevin Walzer
Code by Kevin
http://www.codebykevin.com

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web