2 years ago

#37368

test-img

Rattfratz

Calling .destroy() by using a string

I would like to kill the main tkinter window by passing a string, but the following code doesn't execute correctly:

from tkinter import *

btncmd = "win.destroy"

def killwin():
    eval(btncmd)
    
win=tk.Tk()

MyButton=ttk.Button(win, command=killwin)

win.mainloop()

The function killwin() is called but the main window isn't destroyed.

tkinter

destroy

0 Answers

Your Answer

Accepted video resources