I have a sentence generator that I set up with a "make" button to print the generated sentence, but I want it to print to the resultBox area, and instead it prints to the terminal window. I'm assuming it has something to do with the return sentence portion of it. But any help would be appreciated
class MainFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, title = 'Sentence Generator',
pos = (200, 75), size = (WINDOW_WIDTH, WINDOW_HEIGHT))
self.background = wx.Panel(self)
self.makeBtn = wx.Button(self.background, label = 'Make')
self.makeBtn.Bind(wx.EVT_BUTTON, self.displaySentence)
self.resultBox = wx.TextCtrl(self.background, style = wx.TE_READONLY | wx.TE_MULTILINE)
self.hBox = wx.BoxSizer()
self.hBox.Add(self.resultBox, proportion = 1, border = 0)
self.hBox.Add(self.makeBtn, proportion = 0, border = 0)
self.vBox = wx.BoxSizer(wx.VERTICAL)
self.vBox.Add(self.hBox, proportion = 0, flag = wx.EXPAND, border = 0)
self.vBox.Add(self.result, proportion = 1, flag = wx.EXPAND, border = 0)
self.background.SetSizer(self.vBox)
self.Show()
def displaySentence(self, event):
for item in self.makeSentence(part1, part2, part3):
print item
def resultBox(self, event):
self.resultBox.SetValue(self.makeSentence.GetValue())
def makeSentence(self, part1, part2, part3, n=1):
"""return n random sentences"""
#convert to lists
p1 = part1.split('\n')
p2 = part2.split('\n')
p3 = part3.split('\n')
#shuffle the lists
random.shuffle(p1)
random.shuffle(p2)
random.shuffle(p3)
#concatinate the sentences
sentence = []
for k in range(n):
try:
s = p1[k] + ' ' + p2[k] + ' ' + p3[k]
s = s.capitalize() + '.'
sentence.append(s)
except IndexError:
break
return sentence