1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
#!/usr/bin/python
# coding: utf-8
#
# n: nombre de chiffres
# i: indice pour la liste des couleurs i%3 ; et limite la longueur de la saisie
#
import wx
nb = 3 # ne pas dépasser 7 !!, arbitraire ici.
i = 0
dys_color = [ 'GREEN','RED','BLUE']
def onCharEvent(event):
keycode = event.GetKeyCode()
if keycode in range(48,58):
#
i = text.GetLastPosition()
if i >= nb:
i = nb
text.SetInsertionPoint(nb)
else:
text.SetDefaultStyle(wx.TextAttr(dys_color[i%3]))
text.AppendText(chr(keycode))
app = wx.App(False)
frame = wx.Frame(None)
panel = wx.Panel(frame)
text = wx.TextCtrl(panel,-1, style= wx.TE_MULTILINE, size=(100,35))
font = wx.SystemSettings_GetFont(wx.SYS_SYSTEM_FONT)
font.SetPointSize(20)
text.SetFont(font)
text.Bind(wx.EVT_CHAR, onCharEvent)
frame.Show()
app.MainLoop() |
Partager