ユーザーがテキストを入力し、特定の単語を太字にする単純な GUI を作成しようとしています。グラフィックライブラリを使用していますが、「str」オブジェクトの取得には属性「draw」がありません。また、ウィンドウはほぼ瞬時に閉じます。
from graphics import *
win = GraphWin("Hangman", 600, 600)
win.setBackground("yellow")
textEntry = Entry(Point(233,200),50)
textEntry.draw(win)
# click the mouse to signal done entering text
win.getMouse()
text = textEntry.getText()
testText = Text(Point(150,15), text)
testText.draw(win)
finalOut = ""
outtxt = text
outtxtSplit = outtxt.split()
for word in outtxtSplit:
if word == "bold":
finalOut = finalOut + word.setStyle("bold")
else:
finalOut = finalOut + word
outtxt.draw(win)
exitText = Text(Point(200,50), outtxt)
exitText.draw(win)
win.getMouse()
win.close()