2017-07-25 47 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

相關問題