所以我有两个脚本如下。
脚本1:
while True:
userInput = raw_input(">>> ")
if userInput.lower() in ["yo",'hi', 'hello', 'hi there', 'hey there']:
print "Hi, I'm Jane."
elif userInput.lower() in ["sup", "what's up", "how are you", "how are u", "sup?", "what's up?", "how are you?", "how are u?"]:
whassup = ['Not much, you?','The usual!', 'Working on paperwork.', 'Helping out, haha.', 'Annoying my sisters.']
print(random.choice(whassup))
elif userInput.lower() in ["cool", "awesome", "sounds cool", "rad"]:
print "Aww, thanks!"
else:
print "Sorry, I can only use SpeedChat."
然后,这里是脚本 2,它是此处示例代码的略微编辑版本:
#add some text
bk_text = "This is my Demo"
userin = OnscreenText(text = bk_text, pos = (0, 0.7),
scale = 0.07,fg=(0,0,0,1),align=TextNode.ACenter,mayChange=1)
userin.setFont(font)
#callback function to set text
def setText(textEntered):
userin.setText(textEntered)
#clear the text
def clearText():
b.enterText('')
#add button
b = DirectEntry(text = "" ,scale=.05, command=setText,
initialText="Type Something", numLines = 2,focus=1,focusInCommand=clearText)
所以喜欢。我想要做的是让用户将他们的输入输入到 DirectEntry 框中,这样 Panda3D 面板(有一个动画角色,但不相关)会打印出程序的响应。
即用户输入“你好!” 所以程序会继续吐出“嗨,我是简”。屏幕上。
我对编码非常陌生,实际上我最终做的每件事都非常复杂;稍微解释一下会很有帮助!!太感谢了!