简体   繁体   English

Tk python代码被忽略了吗?

[英]Tk python code is ignored?

I'm making a GUI based game but for some reason a couple of lines in my code are not doing anything at all, when i know they should be. 我正在做一个基于GUI的游戏,但是由于某种原因,当我知道应该这样做时,我的代码中的几行根本没有做任何事情。

def inspect():
     if 'camera' in inv:
     out1.config(text="there's nothing unusual here")
     darts()

For some reason, darts() and out1.config() are completely ignored in this specific part of the code. 由于某些原因,在此代码的特定部分中,darts()和out1.config()被完全忽略。

I know the if statement runs as it should, I have used some print statements to make sure. 我知道if语句可以正常运行,我使用了一些print语句来确保。 the function is called at the right time, and inv does contain 'camera'. 该函数在正确的时间被调用,并且inv确实包含“ camera”。

I have used different text in out1.config(),but no matter what this line wont do anything. 我在out1.config()中使用了不同的文本,但是无论此行什么都不做。

the code simply continues on after as normal, as if the if statement never ran, and just does what would happen if the statement returned false. 代码只是像往常一样继续运行,就好像if语句从未运行过一样,并且只要语句返回false就会发生什么。 everything past then runs fine, everything before runs fine. 过去的一切都运行良好,之前的一切都运行良好。

This bit of code worked perfect before, but just when i came back to do some more work on it it suddenly dosnt work. 这段代码以前工作得很完美,但是当我回来做更多的工作时,它突然变得不起作用了。

Here is the GUI part: 这是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()

EVERYTHING else that uses this works as it should. 使用此功能的所有其他功能均应正常运行。

This is the part of code that inspect() is in: 这是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')

The code basicly does this: if you look at the deartboard you see a glass ball. 该代码基本上是这样做的:如果您查看飞镖板,则会看到一个玻璃球。 if you look closer you see its a camrea. 如果您近距离观察,则会看到其凸凹。 you have the option to take it. 您可以选择接受。 ten if you were to look at the dartboard again, it should say nothing usual here, if you had already taken the camera. 十,如果您要再次查看飞镖,如果您已经拿了相机,则在这里应该没有什么常说的。

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'

In case of doubts, try putting enough prints that you can track what exactly occurs. 如有疑问,请尝试放置足够的打印件,以跟踪发生的确切情况。 I bet that, unlike what you deduced, they will not output an inv with 'camera' in it but at the same print --> no . 我敢打赌,与您推论的不同,他们不会输出带有“ camera”的inv,而是以相同的打印输出--> no

A better idea is to replace all these prints with import pdb; pdb.set_trace() 一个更好的主意是用import pdb; pdb.set_trace()替换所有这些打印import pdb; pdb.set_trace() import pdb; pdb.set_trace() and then use the debugger. import pdb; pdb.set_trace() ,然后使用调试器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM