Python Basics Tutorial Tkinter Yes or No Pop Up Window to Exit

preview_player
Показать описание
Learn how to use a yes or no pop up window to exit from tkinter for python programming

twitter: @python_basics

#pythonprogramming #pythonbasics #pythonforever
Рекомендации по теме
Комментарии
Автор

Finally what i need for a save reminder if closed out by accident

fentonmsu
Автор

im just re watched your view several times, i am trying to get the cancel command to work so the dialog box closes but now it is effecting the exit win_win command to not do it's job and simply loop around... i got it to work by changing the variable to button=cancel. It works


import tkinter as tk
import tkinter.ttk as ttk
import tkinter.messagebox as mbox

win = tk.Tk()

win.title("Window")

win.geometry('300x300')

def press(event):
print('you pressed the button')

def exit_win():
ans = mbox.askyesno('Exit', 'Are you sure')
if ans:
win.destroy()

def cancel_command():
ans = mbox.askyesno('Exit', 'Are you sure')
if ans:
cancel_command()


button = ttk.Button(win, text='Press')
button.bind('<Button-1>', press)

button_exit = ttk.Button(win, text='Exit', command=exit_win)

button = ttk.Button(win, text='Press')
button.bind('<Button-2>', press)

button_cancel = ttk.Button(win, text='Exit', command=cancel_command)

button.pack()
button_exit.pack()

label = ttk.Label(win, text="Hello World")

label.pack()

win.mainloop()

fentonmsu
Автор

i got it to work on my program, but now i am trying to get a save command if accidently closed

fentonmsu