say
say

Reputation: 51

Tkinter menu red message saying menu invoke when resetting and exiting

When I run this and click reset in the menu and then exit in the menu, it gives me this red message:

while executing
"2708519385664reset_option"
(menu invoke)

Anyone know why?

from tkinter import *

def play():
    win = Tk()

    def reset_option():
        win.destroy()
        play()

    menu_widget = Menu(win)
    win.config(menu=menu_widget)
    menu = Menu(menu_widget, tearoff=False)
    menu_widget.add_cascade(label="Menu", menu=menu)

    menu.add_command(label="Reset", command=reset_option)
    menu.add_command(label="Exit", command=exit)

    win.mainloop()

play()

Upvotes: 0

Views: 78

Answers (2)

Enikay
Enikay

Reputation: 61

(Sorry if my English is not good)

It's due to recursivity. If you click on Exit immediately after running the script, there will be no error but if you click at least one time on Reset, you'll get the red message after clicking on Exit. But I don't know why.

I have a similar issue with tkinter and threading but I don't know how to solve it.

Upvotes: 1

Jahan Zabe
Jahan Zabe

Reputation: 49

I check your code i get no anyone error. Reinstall your your code edditer or try another code editer like sublime. I check on Python 3.9

Upvotes: 1

Related Questions