不能调用“事件"命令:应用程序已被销毁 [英] can't invoke "event" command: application has been destroyed

查看:80
本文介绍了不能调用“事件"命令:应用程序已被销毁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我今天在调试我的一些代码并注意到输出中有一条新消息:

So I was debugging some of my code today and noticed a new message in the output:

can't invoke "event" command:  application has been destroyed
     while executing
"event generate $w <<ThemeChanged>>"
     (procedure "ttk::ThemeChanged" line 6)
    invoked from within
"ttk::ThemeChanged"

我在 SO 上查看了有关它的问题,但它们与此错误实例无关.至于 ttk 小部件,我没有在我的代码中使用 ttk 一次,在我的代码中搜索字符串ttk"不会产生任何结果.

I looked at the questions regarding it on SO but they did't relate to this instance of the error. As for the ttk widget, I have not used ttk once in my code, a search for the string "ttk" in my code yields none.

输出这个的代码块:

def GoToEvent(self, controller, driver):

    wait = WebDriverWait(driver, 600)

    var = Vars()
    entertain = var.GetVars("Link")
    if type(entertain) == type(""):
        event = var.GetVars("Event")
        entertain = driver.find_element_by_partial_link_text(event)
    entertain.click()
    try:
        # we have to wait for the page to refresh, the last thing that seems to be updated is the title
        wait.until(EC.title_contains("Entertain"))
    finally:
        # the page is ajaxy so the title is originally this:
        msg = driver.title
        label = tk.Label(self, text=msg, cursor='spinning', font="courier 24", bg="#c63f17")
        label.place(x=self.winfo_width()/2, y=self.winfo_height()/2, anchor="center")
        self.update()   # <--- This is where the problem is
        label.destroy()

这似乎实际上并没有抛出任何错误,而且我的代码运行得非常好.我无法提供足够的代码来重新定位问题,因为在此之前代码太多了,但是如果有帮助,我可以告诉您我所做的所有测试.我调试了这个代码块,发现在 label.destroy() 处添加一个断点仍然会出现这个错误,但在之前的任何地方放置一个断点并跳转到 label.destroy()> 不会打印这个,让我相信这是 self.update() 的某种类型的计时错误,但是当我将 time.sleep(5) 放在和之前在 self.update() 之后,错误仍然存​​在.所以单步执行代码没有显示错误,但 time.sleep() 仍然显示错误.这让我很困惑,我不知道为什么会这样,我写这个程序已经 2 周了,这是第一次发生这种情况.如果没有人知道这很好,代码仍然可以完美运行,我只是好奇这意味着什么以及为什么会发生这种情况.谢谢!

This doesn't seem to actually throw any errors, and my code runs absolutely fine. I can't give enough code to replocate the problem as it is just simply too much code before this, but I can tell you all the testing I did if that helps. I debugged this code block and found that adding a breakpoint at label.destroy() would still give this error, but placing one anywhere before and stepping over to label.destroy() would not print this, leading me to believe it was some type of timing error with self.update(), but when I placed time.sleep(5) before and after self.update() the error was still there. So stepping through the code did not show the error but time.sleep() still showed the error. This puzzles me, I don't know why it would be behaving this way, I have been writing this program for 2 weeks and this is the first time this has happened. If no one knows it's fine, the code still runs perfectly, I'm just curious as to what this means and why it is happening. Thanks!

代码开头:

# !/usr/bin/python
# coding: utf-8
'''
Created on Jun 23, 2017

@author: jacob    <---------------- Line 6

'''


from selenium import webdriver
#from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0
from selenium.webdriver.support import expected_conditions as EC # available since 2.26.0
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException
import os
import platform
import pwd
import re
import time
#import datetime
from time import strftime
import Tkinter as tk     
import tkFont as tkfont  
from Tkinter import Entry, Menu, Menubutton, Canvas

推荐答案

所以这是一个很难找到的错误,因为调试从来没有指向正确的代码区域我不得不通读代码以试图找到一些错误.因此该程序获取用户输入的关键字,然后搜索网站以查找包含该关键字的事件,然后将它们放入下拉菜单中.如果关键字只出现一次或没有出现,则不会显示菜单,它要么单击该事件,要么向用户提示与他们的关键字最接近的建议事件.这似乎是发生此错误的可能区域,因为它仅在未显示菜单时发生.代码如下:

So this was a very hard error to find, as debugging never pointed to the right area of code I had to read through the code to try to find something off. So the program gets user input for a keyword, a website is then searched for the events containing this keyword, they are then put into a drop down menu. If there is only one or none occurrence of the keyword then there is no menu displayed and it either clicks the event or it prompts the user with a suggested event that is closest to their keyword. This seemed like the probable area where this error was happening because it only occurred when no menu was displayed. Code from this:

    if (len(options) > 1):

        button6 = tk.Button(selectMenu, text="Enter",
                        cursor='pointinghand', command=lambda: self.GetSelection(str(var.GetVars("Selection")), links, options, selectMenu, controller))  

        msg = "Which one would you like to attend?"
        label = tk.Label(selectMenu, text=msg, font="Helvedica 14")
        label.pack(side='top', pady=10)
        menbutton.pack(side="top", pady=10)        
        button6.pack(pady=10)

        self.Progress()

        selectMenu.attributes('-topmost', True)
        selectMenu.mainloop()
    elif options:
        var.SendVars("selLink", links[0])
        selectMenu.destroy()
        self.Progress()
    else:
        var.SendVars("Link", 'NO-LINK-FOUND')
        selectMenu.destroy()
        self.Progress()

事实证明,此错误是由在 tk 窗口中创建的 Menubutton 引起的,但从未到达主循环,即使它已被销毁.当到达另一个 tk 窗口的主循环时抛出错误.因此,要解决此问题,您将创建 Menubutton 的位置移动到它将到达其主循环的位置,如下所示.

It turns out that this error was caused by a Menubutton being created in a tk window but never reaching the mainloop, even though it was destroyed. The error is thrown when the mainloop of another tk window is reached. So to fix this you move the creation of the Menubutton to a place where it will reach it's mainloop as below.

这篇关于不能调用“事件"命令:应用程序已被销毁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆