wxPython: StaticText Event

D

David

Plaese look at this simple class.

import wx


class MyFrame(wx.Frame):
def __init__(self, parent, id):
wx.Frame.__init__(self, parent, id, "Hide test", size=(160,160))

# create widgets
self.pnl = wx.Panel(self)
self.st = wx.StaticText(self.pnl, -1,
"Static Text Control", pos=(30,20))
self.tc = wx.TextCtrl(self.pnl, -1, pos=(30,100))
self.Layout()

# Binding
self.st.Bind(wx.EVT_ENTER_WINDOW, self.OnEnterStArea)
self.tc.Bind(wx.EVT_ENTER_WINDOW, self.OnEnterTcArea)

def OnEnterStArea(self, event):
print "Mouse entering in STATIC text control area"

def OnEnterTcArea(self, event):
print "Mouse entering in text control area"

app = wx.PySimpleApp()
frame = MyFrame(None, -1)
frame.Show()
app.MainLoop()


Hovering mouse over the StaticText Control should generate an
EVT_ENTER_WINDOW event like the TextCtrl Control, but it does not happen.

How can I make the StaticText event working?

thank you
David
 
J

John McMonagle

Hovering mouse over the StaticText Control should generate an
EVT_ENTER_WINDOW event like the TextCtrl Control, but it does not happen.

How can I make the StaticText event working?

According to the book "wxPython In Action", page 186:

"One feature that you cannot see from just the figure is that the
wx.StaticText window never receives or responds to mouse events, and
never takes the user focus."



If you want to create static text that responds to mouse events, try
using the wx.lib.stattext.GenStaticText class.

Add the following import:

import wx.lib.stattext

Then,

self.st = wx.lib.stattext.GenStaticText(self.pnl, -1, 'Static Text
Control', pos=(30,20))

Regards,

John
 
A

Amaury Forgeot d'Arc

David a écrit :
Plaese look at this simple class. (...code...)
Hovering mouse over the StaticText Control should generate an
EVT_ENTER_WINDOW event like the TextCtrl Control, but it does not happen.

How can I make the StaticText event working?

I quick Google search found the following thread:

http://lists.wxwidgets.org/archive/wx-users/msg31855.html
or
http://lists.wxwidgets.org/archive/wx-users/msg31983.html

It suggest that you use another kind of control instead.
Is a disabled TextCtrl acceptable?

Hope this helps,
 
D

David

Il Fri, 08 Sep 2006 10:24:52 +1000, John McMonagle ha scritto:
If you want to create static text that responds to mouse events, try
using the wx.lib.stattext.GenStaticText class.

Add the following import:

import wx.lib.stattext

Then,

self.st = wx.lib.stattext.GenStaticText(self.pnl, -1, 'Static Text
Control', pos=(30,20))

Thankyou very much!

Best regards,

David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top