2016-05-22 8 views
-3

私は今Python(2.7)を使っていますが、クラスを使い始めました。それはGameIntroが定義されていないことを私に伝えます。私はそれを修正しようとしてきたが、それが動作するように望んでいない:私が定義した関数が定義されていないとPythonが言っているのはなぜですか?

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')) 
+0

。 –

+0

これが有効なPythonコードのような行 'クラスの勝利の後には、インデント()がないように、それは、見ていません:' – jolvi

+0

私はクラスの上GameIntroを入れてみましたが、それはテキスト1とbutt1のような変数がなかったことを言いました作業 – DefecateRainbows

答えて

0

関数は、ウィンドウが存在している間、それが定義されていないことを意味する、mainloop終了後まで定義されていません。関数を呼び出すコードが実行される前に、def GameIntroをどこかに置かなければなりません。 this`を追加する - あなたはライン `win.butt1.configure(win.root、テキスト= '続行'、フォント=( 'MSセリフ'、12 '太字'))#<内の別の決算括弧が必要

関連する問題