【发布时间】:2016-09-19 09:39:29
【问题描述】:
我使用 Python(2.7) 已经有一段时间了,但刚刚开始使用类。它告诉我 GameIntro 没有定义。我一直在尝试修复它,但它不想工作:
import random
from Tkinter import *
import time
class win():
root = Tk()
root.wm_title("HauntFall")#Title of window
text1 = Label(root, text = "HAUNTFALL", font = ('MS Serif', 50, 'bold'), fg = "white", bg = "black")
text1.pack()#This one and ^ that one make the big lettered HauntFall.
butt1 = Button(root, text = "PLAY", font = ('MS Serif', 15, 'bold'), fg = 'red', command = GameIntro)
butt1.pack(pady = 3)#These two make the PLAY button.
root.configure(bg='black')#This one sets the background to black.
root.mainloop()#Puts the window in a loop, so it doesn't immediately close.
def GameIntro():
x = win()
print "Gj"
x.text1.configure( font = ('MS Serif', 12, 'bold'),text = "You approach a house abandoned many years ago - though you can hear faint creaking, and various other noises coming from inside it's shadowy depths. You approach the large wooden doors, and stare up at all 3 stories of the horrifing place. The house has always been a mystery, and although you are the curious type, you have been hesitant to go in. You promise yourself not to succumb to your fears, and you pull open the old wooden doors.", wraplength = 500)
x.butt1.configure( text = 'Continue', font = ('MS Serif', 12, 'bold'))
【问题讨论】:
-
您需要在
win.butt1.configure(win.root, text = 'Continue', font = ('MS Serif', 12, 'bold') )#<--add this行中添加另一个右括号。 -
这看起来不是有效的 Python 代码,因为在
class win():行之后没有缩进 -
我尝试将 GameIntro 放在类上方,但它说 text1 和 butt1 等变量不起作用