Apr-12-2020, 02:13 AM
Hello all,
When my program is run, it prompts for a table name. After entering a table name and clicking on the "Delete Fields" button, the delete_fields subroutine gets called. The delete_fields subroutine calls the get_password subroutine which opens a new window and prompts for a password. After entering the password and clicking on the "Confirm Delete" button, the confirm_delete subroutine checks if the password is correct.
Depending if the password matches, I need the confirm_delete subroutine to return True or False back to the delete_fields subroutine to determine whether or not to delete the fields. Unfortunately, the code is not working.
If somebody can figure out what is wrong with the code, it would be greatly appreciated.
Thanks in advance.
When my program is run, it prompts for a table name. After entering a table name and clicking on the "Delete Fields" button, the delete_fields subroutine gets called. The delete_fields subroutine calls the get_password subroutine which opens a new window and prompts for a password. After entering the password and clicking on the "Confirm Delete" button, the confirm_delete subroutine checks if the password is correct.
Depending if the password matches, I need the confirm_delete subroutine to return True or False back to the delete_fields subroutine to determine whether or not to delete the fields. Unfortunately, the code is not working.
If somebody can figure out what is wrong with the code, it would be greatly appreciated.
Thanks in advance.
from tkinter import * from tkinter import ttk import tkinter.font as font from config import hostname,username,passwd def confirm_delete(new_window,pwd): if (pwd.get() == passwd): new_window.destroy() return(True) else: new_window.destroy() return(False) def get_password(): new_window = Toplevel(mw) new_window.wm_title("Enter Credentials") new_window.geometry('700x200+400+200') new_frame2 = Frame(new_window) new_frame3 = Frame(new_window) new_frame2.pack(side=TOP,fill=X) new_frame3.pack(side=BOTTOM,fill=X) label1 = Label(new_frame2, text="Password",font=("Times",16)) label1.grid(row=1,column=0) pwd = Entry(new_frame2,width=40,font=("Times",16),show="*") pwd.grid(row=1,column=1) btn = Button(new_frame3,text='Confirm Delete',font=("Times",16),command= lambda:confirm_delete(new_window,pwd)).pack() new_window.mainloop() def delete_fields(): print("Entering delete_fields subroutine") if get_password(): print("Deleting fields") print("Leaving delete_fields subroutine") # Start the main program here if __name__ == "__main__": current_file = __file__ mw=Tk() mw.geometry('700x200+400+200') mw.title(current_file) frame2 = Frame(mw) framebot = Frame(mw) frame2.pack(side=TOP,fill=X) framebot.pack(side=BOTTOM,fill=X) w2 = Label(frame2, text="Table Name: ",font=("Times",16)).pack(side="left") a2 = ttk.Combobox(frame2,width=40,font=("Times",16)) a2.pack(side="left") btn2 = Button(framebot,text='Delete Fields',font=("Times",16),command=delete_fields).pack(side="left") btn6 = Button(framebot,text='Exit',font=("Times",16),command=mw.quit).pack(side="right") mw.mainloop()