0

In my App, I create somes class. But I try to close the window. But is not the good method. How I do to close a window class?

I try to destroy and quit and nothing.

That is the actual window I want to close.

import mysql.connector
from tkinter import messagebox
from tkinter import *
from tkinter import ttk
import sqlite3
import tkinter as tk
import os
import configparser

class SelectDB:
    def __init__(self, select_DB_form) :
        self.center_screen()
        self.select_DB_form = select_DB_form
        self.select_DB_form.title ('App')
        ttk.Label(self.select_DB_form, text="Select you're Database:").grid (row = 0, column = 0)
        self.cmb = ttk.Combobox(self.select_DB_form, width="10", values=("Local (sqllite)","MYSQL"))
        self.cmb.grid (row = 0, column = 1)
        btn = ttk.Button(text="Start", command=self.checkcmbo).grid (row = 1, column = 0)
    def checkcmbo(self):
        if self.cmb.get() == "Local (sqllite)":
            messagebox.showinfo("What user choose", "you choose Local (sqllite)")
        elif self.cmb.get() == "MYSQL":
            MysqlForm.mysql_form()###1<--When i open. I want close 2 
            select_DB_form.destroy()###2<-- What i want to close
        else:
            messagebox.showwarning('App','You must choose something!')

    def center_screen(self):
        window_height = 50
        window_width = 275
        select_DB_form.resizable(0, 0)
        screen_width = select_DB_form.winfo_screenwidth()
        screen_height = select_DB_form.winfo_screenheight()
        x_cordinate = int((screen_width/2) - (window_width/2))
        y_cordinate = int((screen_height/2) - (window_height/2))
        select_DB_form.geometry("{}x{}+{}+{}".format(window_width, window_height, x_cordinate, y_cordinate))

That is the window i call with the button and i select mysql in the combobox.

class MysqlForm():
    def mysql_form():
        def center_screen():
            window_height = 150
            window_width = 300
            master.resizable(0, 0)
            screen_width = master.winfo_screenwidth()
            screen_height = master.winfo_screenheight()
            x_cordinate = int((screen_width/2) - (window_width/2))
            y_cordinate = int((screen_height/2) - (window_height/2))
            master.geometry("{}x{}+{}+{}".format(window_width, window_height, x_cordinate, y_cordinate))

        master = Tk()
        master.title ('App - Create DataBase MYSQL')
        center_screen()

        host = tk.StringVar()
        port = tk.StringVar()
        database_name = tk.StringVar()
        database_user = tk.StringVar()
        database_password = tk.StringVar()

        Label(master, text="HOST:").grid(row=0)
        Label(master, text="PORT:").grid(row=1)
        Label(master, text="DATABASE NAME:").grid(row=2)
        Label(master, text="DATABASE USER NAME:").grid(row=3)
        Label(master, text="DATABASE PASSWORD:").grid(row=4)

        e1 = Entry(master, textvariable=host)
        e2 = Entry(master, textvariable=port)
        e3 = Entry(master, textvariable=database_name)
        e4 = Entry(master, textvariable=database_user)
        e5 = Entry(master, textvariable=database_password)

        e1.grid(row=0, column=1)
        e2.grid(row=1, column=1)
        e3.grid(row=2, column=1)
        e4.grid(row=3, column=1)
        e5.grid(row=4, column=1)

        def write_slogan():
            print("FFFFFFFF")

        slogan = Button(master,text = 'Create',command=write_slogan).grid (row = 5, column = 0)
        #master.iconbitmap(r'./local/pics/App.ico')
        master.mainloop()

if __name__ == '__main__':
    select_DB_form = Tk()
    application = SelectDB(select_DB_form)
    #select_DB_form.iconbitmap(r'./local/pics/App.ico')
    select_DB_form.mainloop()

I don't have errors messages. But the window from class 'SelectDB' doesn't close. I do not know if it is possible to perform.

Ivan Kaloyanov
  • 1,748
  • 6
  • 18
  • 24
Manada
  • 61
  • 9
  • You can't close `select_DB_form`, it's your `root` Window wich will terminate `tkinter`. Why don't you use the pattern from the [link](https://stackoverflow.com/a/7557028/7414759) given in [your previous Question](https://stackoverflow.com/questions/55847209/open-class-from-selected-combobox)? Read [Why are multiple instances of Tk discouraged?](https://stackoverflow.com/questions/48045401/why-are-multiple-instances-of-tk-discouraged) – stovfl Apr 26 '19 at 10:17
  • Sorry for the duplicate, i forget. Ok, i try this. Thanks you for reply. – Manada Apr 26 '19 at 10:49

0 Answers0