hi and welcome.
How can I format the text in the self.verify box according to the conditions entered in the onsend function where if the first condition is met (the answer is true) the text in the self.verify box is written in blue, and if the second condition is met the text is written in red? Are there additional values in self.verify.write that can be used for this purpose or what?
Code:
import wx
import winsound
enletters= ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
class lten(wx.Frame):
def __init__(self, parent, school):
super(lten,self).__init__(parent,-1, title= 'Education system, english letters')
self.p = wx.Panel(self,-1)
self.Center()
self.lettern= (0)
self.letter= (enletters[self.lettern])
wx.StaticText(self.p, -1, "answers: ")
self.verify = wx.TextCtrl(self.p, -1, style=wx.TE_READONLY+wx.TE_MULTILINE+wx.HSCROLL)
self.wt= wx.StaticText(self.p, -1, f"type {self.letter} ")
self.write = wx.TextCtrl(self.p, -1)
self.write.SetFocus()
self.send= wx.Button(self.p, -1, "Submit the answer")
self.send.Bind(wx.EVT_BUTTON, self.onsend)
self.Show()
def onsend(self, event):
self.result= self.write.GetValue()
if self.result == self.letter:
self.verify.write(f'''true {self.letter}
''')
winsound.PlaySound('data\\yes.wav', 1)
if self.lettern == 25:
self.lettern= (0)
else:
self.lettern= self.lettern+1
self.letter= (enletters[self.lettern])
self.wt.SetLabel(f"type {self.letter} ")
self.write.SetFocus()
self.write.SetValue("")
elif self.result != self.letter:
self.verify.write(f'''no
''')
winsound.PlaySound('data\\no.wav', 1)
self.write.SetFocus()
self.write.SetValue("")
app = wx.App()
lten(None, None)
app.MainLoop()