[英]Tk python code is ignored?
我正在做一個基於GUI的游戲,但是由於某種原因,當我知道應該這樣做時,我的代碼中的幾行根本沒有做任何事情。
def inspect():
if 'camera' in inv:
out1.config(text="there's nothing unusual here")
darts()
由於某些原因,在此代碼的特定部分中,darts()和out1.config()被完全忽略。
我知道if語句可以正常運行,我使用了一些print語句來確保。 該函數在正確的時間被調用,並且inv確實包含“ camera”。
我在out1.config()中使用了不同的文本,但是無論此行什么都不做。
代碼只是像往常一樣繼續運行,就好像if語句從未運行過一樣,並且只要語句返回false就會發生什么。 過去的一切都運行良好,之前的一切都運行良好。
這段代碼以前工作得很完美,但是當我回來做更多的工作時,它突然變得不起作用了。
這是GUI部分:
global a , b , c , d ,out1 , main_menu,out2
main_menu.destroy()
window=gui.Tk()
global window
actions1 = gui.Frame(window)
out2 = gui.Label(window,text='Brefing room ; Cmdr Forge')
out1 = gui.Message(window,text='ok')
line = gui.Label(text='-------------------------------------------------------------')
a = gui.Button(window,text = 'a')
b = gui.Button(window,text = 'b')
c = gui.Button(window, text = 'c')
d = gui.Button(window, text = 'd')
out2.pack()
line.pack()
out1.pack(side='right')
actions1.pack()
a.pack()
b.pack()
c.pack()
d.pack()
start()
window.mainloop()
使用此功能的所有其他功能均應正常運行。
這是inspect()位於的代碼部分:
def darts():
def inspect():
if 'camera' in inv:
out1.config(text="there's nothing unusual here")
darts()
def inspect_glass():
def remove():
out1.config(text = 'you now have a minature video camera. If only you knew where to plug it in so you could see the footage.')
inv.append('camera')
darts()
out1.config (text="on closer inspection it appears to be a lens of a minature video camrea. it is not one of the agency's, it looks different from the ones they use.")
a.config (text='remove camrea',command = remove)
out1.config(text='above the dartboord apears to be a small glass ball, pressed firmly into the wall')
a.config(text='look closer',command = inspect_glass)
a.config(text='look at dartboard', command = inspect)
b.config(text='play darts', command = play_darts)
c.config(text='do something elce', command = commons)
out2.config(text='Common room ; darts')
該代碼基本上是這樣做的:如果您查看飛鏢板,則會看到一個玻璃球。 如果您近距離觀察,則會看到其凸凹。 您可以選擇接受。 十,如果您要再次查看飛鏢,如果您已經拿了相機,則在這里應該沒有什么常說的。
def inspect():
print '-*- HERE -*-'
print inv
print 'camera' in inv
if 'camera' in inv:
print '--> yes'
out1.config(text="there's nothing unusual here")
darts()
else:
print '--> no'
如有疑問,請嘗試放置足夠的打印件,以跟蹤發生的確切情況。 我敢打賭,與您推論的不同,他們不會輸出帶有“ camera”的inv,而是以相同的打印輸出--> no
。
一個更好的主意是用import pdb; pdb.set_trace()
替換所有這些打印import pdb; pdb.set_trace()
import pdb; pdb.set_trace()
,然后使用調試器。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.