Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can't invoke "event" command: application has been destroyed

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"

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.

Chunk of code that outputs this:

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

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!

Beginning of code:

# !/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
like image 399
Jake Avatar asked Oct 17 '22 08:10

Jake


1 Answers

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

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.

enter image description here

like image 118
Jake Avatar answered Oct 21 '22 04:10

Jake