我正在学习制作Mad Libs生成器,除创建按钮外,我大部分工作已完成。由于某种原因,无法识别命令。我使用Pycharm是因为我的笔记本电脑不允许我点子安装东西(相信我,我已经尝试多次修复它。它只是不想这么做)并且无法安装常规tkinter,所以我拥有Tkintereasy。它说它是在 init 下定义的命令,但它似乎不起作用。这是代码:
def madlib1():
animal = input('Please enter an animal: ')
noun = input('Please enter a noun: ')
place = input('Please enter a place: ')
age = input('Please enter an age: ')
color = input('Please enter a color: ')
adjective = input('Please enter an adjective: ')
noun2 = input('Please enter a noun: ')
verb = input('Please enter a verb: ')
adverb = input('Please enter an adverb: ')
print(
"The wild and ferocious " + animal + " eats plenty of " + noun + " to stay strong and survive in the " + place + ". " +
"\n The" + animal + " lives to be the ripe old age of " + age + "." +
"\n They come in many colors, but primarily, you will see them as " + color + ". " +
"They typically take refuge in the" + adjective + noun2 + " where they " + verb + " in a very " + adverb + " manner.")
# Madlib 2: The professional
def madlib2():
profession = input('Please enter a profession: ')
adjective = input('Please enter an adjective: ')
noun = input('Please enter a noun: ')
celebrity = input('Please enter a celebrity name: ')
adjective2 = input('Please enter an adjective: ')
verbing = input('Please enter a verb ending in ing')
print("Have you ever considered " + profession + " to be your profession? "
"\nThis new " + adjective + " career is the new in demand craze among all the " + noun + ". "
"\nIf you don't believe me, just ask " + celebrity + ". "
"\nThis new" + adjective2 + " job has got me " + verbing + " in my seat!")
Button(root, text='The ferocious animal', font='arial 15', command=madlib1,
bg='ghost white').place(x=60, y=120)
Button(root, text='The professional', font='arial 15', commmand=madlib2,
bg='ghost white').place(x=70, y=180)
root.mainloop()
答案 0 :(得分:0)
简单的错字。
第二个按钮的命令中有3个“ m”:
Button(root, text='The ferocious animal', font='arial 15', command=madlib1, bg='ghost white').place(x=60, y=120)
Button(root, text='The professional', font='arial 15', command=madlib2, bg='ghost white').place(x=70, y=180) # fixed