我正在制作基于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')
代码基本上是这样做的: 如果你看看deartboard,你会看到一个玻璃球。如果你仔细观察,你会看到它的凸轮。你可以选择接受它。十,如果你再次看飞镖牌,如果你已经拿走了相机,那么在这里应该没什么可说的。
答案 0 :(得分:0)
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'
如果有疑问,请尝试放置足够的打印件,以便跟踪确切的情况。我打赌,与你推断的不同,它们不会输出带有“相机”的inv,而是输出相同的--> no
。
更好的想法是用import pdb; pdb.set_trace()
替换所有这些打印,然后使用调试器。