Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python';str';对象没有属性';绘制';使用Zelle graphics.py时_Python_Python 3.x_Zelle Graphics - Fatal编程技术网

Python';str';对象没有属性';绘制';使用Zelle graphics.py时

Python';str';对象没有属性';绘制';使用Zelle graphics.py时,python,python-3.x,zelle-graphics,Python,Python 3.x,Zelle Graphics,我正在尝试创建一个简单的GUI,用户在其中输入一些文本,我将某些单词加粗。我正在使用图形库,但是我的a获取的“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

我正在尝试创建一个简单的GUI,用户在其中输入一些文本,我将某些单词加粗。我正在使用图形库,但是我的a获取的“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() 
你的

outtxt=text

应该是

outtxt = Text(Point(150,15), text)
                      /|\
                       | Put the size you want here.
在您的代码中,
outtxt
文本本身,因此它没有名为
draw()
的方法

outtxt=text

应该是

outtxt = Text(Point(150,15), text)
                      /|\
                       | Put the size you want here.

在您的代码中,
outtxt
text
文本本身,因此它没有名为
draw()

的方法。除了回答和注释中指出的
text()
Point()
参数外,这一行根本不起作用:

finalOut = finalOut + word.setStyle("bold")
正如
finalOut
word
是Python
str
实例,graphics.py
setStyle(“bold”)
方法适用于
Text()
对象


修复此问题与删除此功能相比,可能比较棘手,因为您需要收集普通和粗体
Text()
实例的列表,并以适当的间距将它们绘制在水平行中。graphics.py不会有多大帮助,因为我看不到任何获得格式化文本宽度的方法。似乎style对于整个文本消息而言是全部或全部,而不是单个元素。

除了回答和评论中指出的
text()
Point()
参数之外,这一行根本不起作用:

finalOut = finalOut + word.setStyle("bold")
正如
finalOut
word
是Python
str
实例,graphics.py
setStyle(“bold”)
方法适用于
Text()
对象

修复此问题与删除此功能相比,可能比较棘手,因为您需要收集普通和粗体
Text()
实例的列表,并以适当的间距将它们绘制在水平行中。graphics.py不会有多大帮助,因为我看不到任何获得格式化文本宽度的方法。似乎style对于整个文本消息而言是全部或全部,而不是单个元素。

outtxt.draw(win)
如果您在
str
对象上调用draw,错误消息会告诉您。您期望的是什么行为?
outtxt.draw(win)
您正在对
str
对象调用draw,错误消息会告诉您。你期待什么样的行为?