在我的App中,我创建了somes类。 但是我试图关闭窗户。但这不是好方法。 如何关闭窗口类?
我试图摧毁并放弃,什么也没有。
那是我要关闭的实际窗口。
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))
这是我使用按钮调用的窗口,然后在组合框中选择mysql。
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()
我没有错误消息。但是类“ SelectDB”的窗口没有关闭。我不知道是否可以执行。