0

I'm a student in software development and I'm developing an application (my first application!) in Python for learning purposes. It works fairly well, and I got almost all of the features working that I want to work.

A short explanation of the program: It's an administrative program to log the members of a sports club. So it has basic functions like adding members, listing members, etc.

For it to be complete, it also needs a function to delete a member. This has always worked fine, but I rarely used the function.

Now after I modified a ttk.Treeview() object so it now sorts by last name, I added a new member to see if it sorts like it should. It did!

Now I wanted to delete that member, but for some reason, it no longer works.

It crashes Python. It doesn't just crash the application, no error, just plain "Pythonw.exe has stopped working".

Here's all the code that belongs to that function:

def dellid(zeid, addwindow):
    winsound.PlaySound("SystemHand", winsound.SND_ASYNC)
    usure = tkinter.Tk()
    print('usure window created')
    usure.title('Lid verwijderen')
    usure.geometry('{}x{}'.format('300', '150'))
    usure.iconbitmap(default='programdata\\icon.ico')
    usure.attributes("-topmost", True)
    addwindow.grab_set()
    #logo2 = PhotoImage(file="warning.png")
    #logolabel = tkinter.Label(usure, image = logo2)
    #logolabel.grid(row01, columnspan = 2)

    usure.columnconfigure(0, weight = 1)
    usure.columnconfigure(1, weight = 2)

    label01 = tkinter.Label(usure, text = '''
Weet U zeker dat U dit lid wilt verwijderen?
Deze actie kan niet ongedaan worden gemaakt!''').grid(row = 1, columnspan = 2)
    emptyrow = tkinter.Label(usure, text = ' ').grid(row = 2, columnspan = 2)
    jaknop = ttk.Button(usure, text = 'Ja', command = lambda: delforsure(zeid, usure, addwindow)).grid(row = 3, column = 0, sticky = 'E')
    neeknop = ttk.Button(usure, text = 'Nee', command = lambda: nodell(addwindow, usure)).grid(row = 3, column = 1, sticky = 'S') 





def nodell(addwindow, usure):
    addwindow.grab_release()
    usure.destroy()



def delforsure(zeid, usure, addwindow):
    #addwindow.grab_release()
    addwindow.destroy()
    print('addwindow destroyed')
    usure.destroy()
    print('usure destroyed')
    conn = sqlite3.connect('test.db')
    c = conn.cursor()

    opendb = []
    opendb.append(zeid)

    print(zeid)
    print(opendb)

    c.execute("DELETE FROM leden WHERE ids = ?",opendb)
    print('c.execute')
    conn.commit()
    print('c.commit')
    #usure.destroy()

    done = tkinter.Tk()
    done.title('Lid verwijdert')
    done.geometry('{}x{}'.format('300', '150'))
    done.iconbitmap(default='programdata\\icon.ico')

    label01 = tkinter.Label(done, text = '''


Lid verwijdert

''')
    label01.pack()

    done.update()
    time.sleep(2)

    on_return(done)

The on_return function closes the said window and reopens the main menu.

Now in delforsure(zeid, usure, addwindow) it locks up on the line usure.destroy()

It doesn't print the line 'usure destroyed' anymore, that I put there to see where it locks up.

It doesn't give any error, Python itself just crashes.

If I move

usure.destroy()
print('usure destroyed')

under on_return(done), all the way at the bottom, it does close the window and return to the main menu, but the main menu will be drawn with graphical distortions and soon still crashes afterwards.

I really don't understand what is going on.

Can anybody help me trace the issue please?

Ajean
  • 5,528
  • 14
  • 46
  • 69
deWaardt
  • 3
  • 2
  • It sounds like you are running this from IDLE, is that right? If so, can you try running this from the command line? – Novel May 04 '17 at 20:35
  • 1
    Reduce your application to the minimum amount of code that exhibits the problem, **then** post it in a question here. – martineau May 04 '17 at 20:37
  • If you are calling `Tk()` and/or `maniloop()` more than once in your program, that's part of the problem If you need extra windows, create instances of `Toplevel`. – Bryan Oakley May 04 '17 at 20:47

1 Answers1

0

It looks like you are making a yes / no modal window. Is there a reason you don't want to use the version that is built into tkinter?

from tkinter import messagebox

def dellid(zeid, addwindow):
    answer = messagebox.askyesno(
        'Lid verwijderen',
        'Weet U zeker dat U dit lid wilt verwijderen?\n'
        'Deze actie kan niet ongedaan worden gemaakt!')
    if answer:
        addwindow.destroy()
        print('addwindow destroyed')
Novel
  • 13,406
  • 2
  • 25
  • 41