2017-07-25 363 views
1

所以我今天调试我的一些代码,发现在输出新的消息:SO关于它不能援引“事件”命令:应用程序已经被破坏

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" 

我看了看问题但它们并没有涉及这个错误的实例。至于ttk小部件,我没有在我的代码中使用过一次ttk,在我的代码中搜索字符串“ttk”不会产生任何结果。

的代码块,它输出这样的:

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() 

这似乎并不实际抛出任何错误,我的代码运行的精绝。我无法提供足够的代码来重新定位问题,因为在此之前它只是代码太多,但如果有帮助,我可以告诉你所有测试。我调试了这个代码块,发现在增加一个断点仍然会出现这个错误,但是放置一个之前的任何地方并且跳到都不会打印这个,导致我相信这是self.update()的某种类型的定时错误,但是当我在self.update()之前和之后放置了time.sleep(5),错误依然存在。因此,单步执行代码并未显示错误,但time.sleep()仍显示错误。这使我感到困惑,我不知道为什么会这样做,我一直在写这个程序2周,这是第一次发生这种情况。如果没有人知道这很好,代码仍然运行完好,我只是好奇这是什么意思,为什么它发生。谢谢!

开头的代码:

# !/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 
+0

只有一个想法,但你尝试'update_idletasks()'? – Gribouillis

+0

错误似乎相当清楚:在根窗口被销毁后,某些东西正在触发回调。不可能说出什么,因为错误提示ttk小部件,并且在您发布的代码中没有任何地方使用ttk小部件。 –

+0

@Gribouillis是的我试过了,没有修复它 – Jake

回答

0

因此,这是一个非常困难的错误找到,因为调试从不指着代码右边的区域我不得不通过代码来读取,试图找到一些关闭。因此,程序获取关键字的用户输入,然后搜索包含此关键字的事件的网站,然后将它们放入下拉菜单中。如果关键字只有一个或没有出现,则没有菜单显示,并且它可以单击该事件,也可以使用与其关键字最接近的建议事件来提示用户。这似乎是发生此错误的可能区域,因为它仅在没有菜单显示时发生。从这个代码:

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() 

事实证明,由上Menubutton在TK窗口创建,但从未达到主循环,即使它被摧毁这个错误造成的。当到达另一个tk窗口的主循环时,会引发该错误。所以要解决这个问题,你需要将Menubutton的创建移动到它将会到达它的主循环的位置,如下所示。

enter image description here

相关问题