【发布时间】:2017-12-31 17:19:27
【问题描述】:
所以我今天调试了一些代码,并注意到输出中有一条新消息:
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”不会产生任何结果。
输出这个的代码块:
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(),但是当我在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
【问题讨论】:
-
只是一个想法,但你试过
update_idletasks()吗? -
这个错误似乎很明显:在根窗口被销毁后,某些东西正在触发回调。不可能说什么,因为错误提到了 ttk 小部件,并且在您发布的代码中没有任何地方使用 ttk 小部件。
-
@Gribouillis 是的,我试过了,没有解决
-
@Brian Oakly 我确实在代码 ttk 小部件中发布过,
tk.Label是一个 ttk 小部件。如前所述,它不是 label.destroy,因为此错误发生在执行 label.destroy 之前。 -
好吧,这是第 6 行,把你自己弄晕了,哈哈。我希望这会有所帮助,但我有 76.59% 的把握确定第 6 行不是问题。至于 ttk 小部件,我没有在我的代码中使用过一次 ttk,在我的代码中搜索字符串“ttk”不会产生任何结果。这就是为什么我很困惑哈哈。
标签: python python-2.7 tkinter