-1

I was wondering how I could get it so the window for tkinter would close when a button is clicked, any help is appreciated. Below is part of my code.

def ynumber_chosen():
    class number:
        def __init__ (self, root):
            root.title('Picking a row')
            root.minsize(width = 3, height = 225)
            root.maxsize(width = 3, height = 225)

            label = Label(root, text = "Pick a row")

            self.button1 = Button(root, text = "1", height = 3, width = 7, command = ynumber1)
            self.button1.grid(row = 0, column = 1)
            self.button1 = Button(root, text = "2", height = 3, width = 7, command = ynumber2)
            self.button1.grid(row = 0, column = 3)
            self.button1 = Button(root, text = "3", height = 3, width = 7, command = ynumber3)
            self.button1.grid(row = 2, column = 1)
            self.button1 = Button(root, text = "4", height = 3, width = 7, command = ynumber4)
            self.button1.grid(row = 2, column = 3)
            self.button1 = Button(root, text = "5", height = 3, width = 7, command = ynumber5)
            self.button1.grid(row = 3, column = 1)
            self.button1 = Button(root, text = "6", height = 3, width = 7, command = ynumber6)
            self.button1.grid(row = 3, column = 3)
            self.button1 = Button(root, text = "7", height = 3, width = 7, command = ynumber7)
            self.button1.grid(row = 4, column = 1)


    root = Tk()
    app1 = number(root)
    mainloop()
martineau
  • 119,623
  • 25
  • 170
  • 301
A. Tim
  • 1
  • 2
    Any basic tkinter tutorial should cover this. What have you tried? Just googling "tkinter quit" gives enough results. – Lafexlos Feb 19 '17 at 18:56

1 Answers1

0

To destroy window you need to call root.destroy() in click command ynumberX() method:

def ynumberX():
    """Do something with number here"""
    root.destroy

You can pass root either as class variable or as argument to ynumberX() method (for more on that topic see Tkinter Callbacks).

martineau
  • 119,623
  • 25
  • 170
  • 301
blami
  • 6,588
  • 2
  • 23
  • 31