我正在尝试使用window.wm_protocol(“ WM_DELETE_WINDOW”,func),但是它会自动运行而无需单击窗口上的X(关闭)按钮。我只想在tkinter窗口关闭时调用回调。
def callback(driver):
driver.close()
def runGUI():
try:
driver = newSession()
#Define window
window = tkinter.Tk()
window.title("Global Warranty RPO Retrieval Tool")
window.geometry("800x600")
vinLbl = tkinter.Label(window, text = "17 Digit VIN:", font="12")
vinLbl.grid(column = 0, row = 1, padx = 4)
vinEntry = tkinter.Entry(font="12")
vinEntry.grid(column = 1, row = 1, padx =4)
entryBtn = tkinter.Button(window, text="Get RPOs", command= lambda:
getGWRPOs(driver, vinEntry.get().upper()))
entryBtn.grid(column = 2, row = 1, padx = 4)
warningLbl = tkinter.Label(window, text = "!!This Tool Will not work with \
IVER builds!!", font="16", fg="red")
warningLbl.grid(column=0, row=2, padx=4, columnspan=3)
window.wm_protocol("WM_DELETE_WINDOW", callback(driver))
window.mainloop()