我目前正在寫一個掛人遊戲。使用Tkinter進行GUI。Python - 如何獲取函數中的字符串?
如何從一個函數得到一個字符串:
def startgame():
player21abel=Label(text=" Guess a Letter ",fg="black").place(x=10,y=60)
mbutton=Button(text=" Press to summit ",command=guess).place(x=220,y=100)
player2=StringVar()
player2input=Entry(textvariable=player2).place(x=220,y=56)
test=""
uetext=utext.get()
def guess():
test=player2.get()
test=""
player2=StringVar
print (test)
我得到的錯誤:
line 16, in guess
test=player2.get()
UnboundLocalError: local variable 'player2' referenced before assignment
我想從player2input並處理它的函數猜測的文本框中輸入。但它不認爲它是一個字符串?
對不起。我不明白你的意思是使用這些命令: – Angus 2014-10-04 09:40:56
app = App() app.startgame()。在即將出現的代碼中,如果我想要一個按鈕進入某個函數,是否需要替換:mbutton = Button(text =「Press to start game」,command = startgame).place(x = 123,y = 100) – Angus 2014-10-04 09:41:47