Bonjour à tous,

Ma question semble très simple et j'ai l'impression de ne toujours pas maîtriser les class. C'est pourquoi j'aimerais comprendre l'exemple suivant :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# !/usr/bin/python
# -*- coding:Latin-1 -*-
 
import wx
import wx.richtext as rt
 
class WidgetRichText(rt.RichTextCtrl):
	def __init__(self, parent):
		rt.RichTextCtrl.__init__(self,parent,size)
		rt.RichTextCtrl(parent, size)
 
	def WriteText(self,text):
		wx.CallAfter(myrichtext1.SetFocus)
		myrichtext1.Freeze()
		myrichtext1.BeginTextColour((255, 0, 0))
		myrichtext1.WriteText("class WidgetRichText")
		myrichtext1.EndTextColour()
		myrichtext1.Thaw()
 
 
class Fentre_prin(wx.Frame):
	def __init__(self, parent, title): 
		wx.Frame.__init__(self, parent, -1, title)
		### ma_scroll_window :
		ma_scroll_window = wx.ScrolledWindow(self)
		ma_scroll_window.SetBackgroundColour(wx.WHITE)
		ma_scroll_window.SetScrollbars(20, 20, 55, 40)
		### Bouton :
		b1 = wx.Button(ma_scroll_window, -1, u"Quitter")
		self.Bind(wx.EVT_BUTTON, self.quitter, b1)
		### RichTextCtrl :
		myrichtext1 = rt.RichTextCtrl(ma_scroll_window,size=(700,400))
		myrichtext1.WriteText('class Fentre_prin')
		# Création du sizer et positionnement des wigets :
		sizer = wx.BoxSizer(wx.VERTICAL)
		sizer.Add(b1, 0, wx.ALL, 5)
		sizer.Add(myrichtext1, 0, wx.ALL, 5)
		# Le sizer est lié au conteneur :
		ma_scroll_window.SetSizer(sizer)
		ma_scroll_window.Layout()
 
	def quitter(self, evt):
		self.Close()
 
 
class MyApp(wx.App):
    def OnInit(self):
        frame = Fentre_prin(None, u"Début")
        self.SetTopWindow(frame)
        frame.Show(True)
        return True
 
try:
	app = MyApp()
 
except:
	app = MyApp(redirect=True)
 
app.MainLoop()
Pourquoi la méthode WriteText() que je définis dans WidgetRichText reste t'elle sans effet ?