Add a Panel;
import wx
class Mywin(wx.Frame):
def init(self, parent, title):
super(Mywin, self).init(parent, title = title,size = (350,250))
panel = wx.Panel(self)
vbox = wx.BoxSizer(wx.VERTICAL)
hbox1 = wx.BoxSizer(wx.HORIZONTAL)
l1 = wx.StaticText(panel, -1, “Text Field”)
hbox1.Add(l1, 1, wx.EXPAND|wx.ALIGN_LEFT|wx.ALL,5)
self.t1 = wx.TextCtrl(panel)
hbox1.Add(self.t1,1,wx.EXPAND|wx.ALIGN_LEFT|wx.ALL,5)
self.t1.Bind(wx.EVT_TEXT,self.OnKeyTyped)
vbox.Add(hbox1)
hbox2 = wx.BoxSizer(wx.HORIZONTAL)
l2 = wx.StaticText(panel, -1, “password field”)
hbox2.Add(l2, 1, wx.ALIGN_LEFT|wx.ALL,5)
self.t2 = wx.TextCtrl(panel,style = wx.TE_PASSWORD)
self.t2.SetMaxLength(5)
hbox2.Add(self.t2,1,wx.EXPAND|wx.ALIGN_LEFT|wx.ALL,5)
vbox.Add(hbox2)
self.t2.Bind(wx.EVT_TEXT_MAXLEN,self.OnMaxLen)
hbox3 = wx.BoxSizer(wx.HORIZONTAL)
l3 = wx.StaticText(panel, -1, “Multiline Text”)
hbox3.Add(l3,1, wx.EXPAND|wx.ALIGN_LEFT|wx.ALL,5)
self.t3 = wx.TextCtrl(panel,size = (200,100),style = wx.TE_MULTILINE)
hbox3.Add(self.t3,1,wx.EXPAND|wx.ALIGN_LEFT|wx.ALL,5)
vbox.Add(hbox3)
self.t3.Bind(wx.EVT_TEXT_ENTER,self.OnEnterPressed)
hbox4 = wx.BoxSizer(wx.HORIZONTAL)
l4 = wx.StaticText(panel, -1, “Read only text”)
hbox4.Add(l4, 1, wx.EXPAND|wx.ALIGN_LEFT|wx.ALL,5)
self.t4 = wx.TextCtrl(panel, value = “ReadOnly Text”,style = wx.TE_READONLY|wx.TE_CENTER)
hbox4.Add(self.t4,1,wx.EXPAND|wx.ALIGN_LEFT|wx.ALL,5)
vbox.Add(hbox4)
panel.SetSizer(vbox)
self.Centre()
self.Show()
self.Fit()
def OnKeyTyped(self, event):
print event.GetString()
def OnEnterPressed(self,event):
print “Enter pressed”
def OnMaxLen(self,event):
print “Maximum length reached”
app = wx.App()
Mywin(None, ‘TextCtrl demo’)
app.MainLoop()
···
On Tue, Jan 17, 2017 at 9:12 AM, swestin@grammatech.com wrote:
I’m working on an application that needs to support multiple platforms. It uses a simple wx.TextCtrl to get user input, which works fine when the code runs on Windows 7 using the native backend. But running on a Linux host (Ubuntu 3.8.0) with the display on my Windows box using the CygWin X11 server, the numeric keypad does nothing. And yes, “Num Lock” is on in both cases.
At this point, I’m even having trouble getting key events from the control. I get the EVT_TEXT_ENTER event just fine, but nothing gets called on EVT_CHAR, EVT_KEY_UP, and EVT_KEY_DOWN, even for keys on the main keyboard. On Windows, all events arrive as expected.
Any hints as to what I’m doing wrong?
–
You received this message because you are subscribed to the Google Groups “wxPython-users” group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.