Window .quit() not working when going to change to another window from another .py module
So my program should when user in an if case (correct) the window will destroy and change into another window from another .py module. This works on tkinter. Down here is the code
base.py where user must enter a correct username and id to enter the user_menu.main_menu
import tkinter as tk
from tkinter import END, messagebox
import customtkinter
import sqlite3
import user_menu
from PIL import ImageTk,Image
customtkinter.set_appearance_mode("dark") # Modes: system (default), light, dark
customtkinter.set_widget_scaling(1.2) # widget dimensions and text size
customtkinter.set_spacing_scaling(1.0) # padding and place positions
customtkinter.set_window_scaling(0.7) # window geometry dimensions
#CustomTkinter Window
root = customtkinter.CTk()
root.title("Quizzaz - Login & Register Form")
#root.geometry("360x300")
#root.iconphoto(True, tk.PhotoImage(file="health.png"))
def login():
#calling data input from user entry
id = entry_id_login.get()
pasw = entry_pass_login.get()
#Databases Connection Thingy
#Connect to a database
conn = sqlite3.connect('database.db')
#DB Cursor for executing db query
c = conn.cursor()
#Query command to identify login data from database
c.execute("SELECT * FROM user WHERE username=? AND password=?",(id, pasw))
#Fetch one data from database
row = c.fetchone()
if row:
root.quit()
messagebox.showinfo('info', 'login success')
user_menu.main_menu()
else:
messagebox.showinfo('info', 'login gagal')
def register():
#Calling (get) data from user input (Entry)
id = entry_id_regis.get()
pasw = entry_pass_regis.get()
# Databases
# Create a database or connect to one
conn = sqlite3.connect('database.db')
# Create cursor
c = conn.cursor()
#Query command to insert (register) data to database
c.execute("INSERT INTO user(username, password) VALUES(?,?)",(id,pasw))
#fetch data from database
row = c.fetchone()
if row:
messagebox.showinfo('info', 'register failed')
else:
messagebox.showinfo('info', 'register success')
conn.commit()
conn.close()
# Clear Text Box
entry_id_regis.delete(0, END)
entry_pass_regis.delete(0, END)
#Login Entry Widget Thingy
login_frame = customtkinter.CTkFrame(root, width=300, height=200, corner_radius=5)
login_frame.grid(column=0, row=0, padx=15, pady=15)
txt_title_login = customtkinter.CTkLabel(login_frame, text="LOGIN FORM")
txt_title_login.pack(anchor=tk.N)
txt_id_login = customtkinter.CTkLabel(login_frame, text="Enter Your ID: ")
txt_id_login.pack(anchor=tk.W)
entry_id_login = customtkinter.CTkEntry(login_frame, placeholder_text="Masukkan ID ")
entry_id_login.pack()
txt_pass_login = customtkinter.CTkLabel(login_frame, text="Enter Your Password: ")
txt_pass_login.pack()
entry_pass_login = customtkinter.CTkEntry(login_frame, show="*", placeholder_text="Masukan Password")
entry_pass_login.pack()
btn_login = customtkinter.CTkButton(login_frame, text="Log In", command=login)
btn_login.pack(pady=10)
#Register Entry Widget
regis_frame = customtkinter.CTkFrame(root, width=300, height=200, corner_radius=5)
regis_frame.grid(column=1, row=0, padx=15, pady=15)
txt_title_regis = customtkinter.CTkLabel(regis_frame, text="REGISTER FORM")
txt_title_regis.pack(anchor=tk.N)
txt_id_regis = customtkinter.CTkLabel(regis_frame, text="Enter Your ID: ")
txt_id_regis.pack(anchor=tk.W)
entry_id_regis = customtkinter.CTkEntry(regis_frame, placeholder_text="Masukkan ID ")
entry_id_regis.pack()
txt_pass_regis = customtkinter.CTkLabel(regis_frame, text="Enter Your Password: ")
txt_pass_regis.pack()
entry_pass_regis = customtkinter.CTkEntry(regis_frame, show="*", placeholder_text="Masukan Password")
entry_pass_regis.pack()
btn_regis = customtkinter.CTkButton(regis_frame, text="Register", command=register)
btn_regis.pack(pady=10)
#Exit Button
btn_exit = customtkinter.CTkButton(root, text="Exit", command=quit)
btn_exit.grid(column=0, row=1, pady=10)
#Admin Button
btn_admin = customtkinter.CTkButton(root, text="Login Admin", )
btn_admin.grid(column=1, row=1, pady=10)
root.mainloop()
down here is the other .py module that should be displayed after user got a correct if case in the previous window
import tkinter as tk
import customtkinter
import sqlite3
import game_easy_ctkinter
import game_medium
import game_hard
from PIL import ImageTk,Image
def main_menu():
customtkinter.set_appearance_mode("dark")
#Root Window Main Menu
menu = customtkinter.CTk()
menu.title("Quizzaz - Main Menu")
menu.geometry("280x250")
#menu.tk.call('wm', 'Iconphoto', menu._w, tk.PhotoImage(file='health.png'))
#This the frame of user menu
difficulty_frame = customtkinter.CTkFrame(menu, width=400, height=400, corner_radius=20, pady=20, padx=10, fg_color="grey")
difficulty_frame.pack(anchor=tk.CENTER)
#Difficulty Button
txt = customtkinter.CTkLabel(difficulty_frame, text="Pilih Tingkat Kesusahan")
txt.pack(pady=10)
btn_easy = customtkinter.CTkButton(difficulty_frame, text="Pemula", command=game_easy_ctkinter.qz_ez_starter, fg_color="green", text_color="white", text_font="arial 12")
btn_easy.pack(pady=3)
btn_medium = customtkinter.CTkButton(difficulty_frame, text="Sedang", command=game_medium.qz_md_starter, fg_color="orange", text_color="white", text_font="arial 12")
btn_medium.pack(pady=3)
btn_hard = customtkinter.CTkButton(difficulty_frame, text="Susah", command=game_hard.qz_hrd_starter , fg_color="red", text_color="white", text_font="arial 12")
btn_hard.pack(pady=3)
#Exit Button
btn_exit = customtkinter.CTkButton(menu, text="KELUAR", command=menu.destroy, text_font="arial 12", fg_color="yellow", text_color="black")
btn_exit.pack(pady=10)
#loop
menu.mainloop()
So after this is where I use tkinter where it should work closing the window after if case correct.
base.py
from tkinter import *
from tkinter import messagebox
from PIL import ImageTk,Image
import sqlite3
from admin_login import *
from user_menu import *
#Tkinter Window
root = Tk()
root.title('Quizzaz - Login Form')
#root.iconbitmap('homer.ico')
# Function Login & Register
def login(self, id, pasw):
#Calling (get) data from user input (Entry)
id = login_id_input.get()
pasw = login_pass_input.get()
# Databases
# Create a database or connect to one
conn = sqlite3.connect('database.db')
# Create cursor
c = conn.cursor()
# Query command to select (login) data from database
c.execute("SELECT * FROM user WHERE username=? AND password=?",(id, pasw))
#fetch one data from database
row=c.fetchone()
if row:
messagebox.showinfo('info', 'login success')
main_menu()
root.destroy()
else:
messagebox.showinfo('info', 'login gagal')
#Commit changes
conn.commit()
#Close Connection
conn.close()
# Clear Text Box
#login_id_input.delete(0, END)
#login_pass_input.delete(0, END)
def register():
#Calling (get) data from user input (Entry)
id = regis_id_input.get()
pasw = regis_pass_input.get()
# Databases
# Create a database or connect to one
conn = sqlite3.connect('database.db')
# Create cursor
c = conn.cursor()
#Query command to insert (register) data to database
c.execute("INSERT INTO user(username, password) VALUES(?,?)",(id,pasw))
#fetch data from database
row = c.fetchone()
if row:
messagebox.showinfo('info', 'register failed')
else:
messagebox.showinfo('info', 'register success')
conn.commit()
conn.close()
# Clear Text Box
regis_id_input.delete(0, END)
regis_pass_input.delete(0, END)
#Login Entry Widget
login_frame = LabelFrame(root, text="Login Form", padx=80, pady=30)
login_frame.grid(column=0, row=0, padx=15, pady=15)
text_id_login = Label(login_frame, text="Enter Your ID: ")
text_id_login.pack()
login_id_input = Entry(login_frame)
login_id_input.pack()
text_pass_login = Label(login_frame, text="Enter Your Password: ")
text_pass_login.pack(pady=10)
login_pass_input = Entry(login_frame, show="*")
login_pass_input.pack()
login_button = Button(login_frame, text="Log In", command=login)
login_button.pack(pady=10)
#Register Entry Widget
regis_frame = LabelFrame(root, text="Register Form", padx=80, pady=30)
regis_frame.grid(column=1, row=0, padx=15, pady=5)
text_id_regis = Label(regis_frame, text="Enter Your ID: ")
text_id_regis.pack()
regis_id_input = Entry(regis_frame)
regis_id_input.pack()
text_pass_regis = Label(regis_frame, text="Enter Your Password: ")
text_pass_regis.pack(pady=10)
regis_pass_input = Entry(regis_frame, show="*")
regis_pass_input.pack()
regis_button = Button(regis_frame, text="Register", command=register)
regis_button.pack(pady=10)
ext_btn = Button(root, text="Exit", command=quit)
ext_btn.grid(column=0, row=1,pady=10)
adm_btn = Button(root, text="Log In As Admin", command=window_login_admin)
adm_btn.grid(column=1, row=1, pady=10)
mainloop()
user_menu.py
from tkinter import *
from tkinter import messagebox
from PIL import ImageTk,Image
from game_hard import *
from game_medium import *
from game_easy import *
import sqlite3
from game_hard import qz_hrd_starter
def main_menu():
#The Root Window of Main Menu
menu = Tk()
menu.title("Quizzaz - Main Menu")
#menu.iconbitmap('homer.ico')
#This Is where user can select radio button difficulty
difficulty_frame = LabelFrame(menu, text="Pilih Tingkat Kesulitan", padx=100, pady=60)
difficulty_frame.pack()
#Difficulty Choosing Button
txt = Label(difficulty_frame, text="Pilih Tingkat Kesusahan").pack(pady=10)
btn_easy = Button(difficulty_frame, text="Pemula", command=qz_ez_starter).pack(pady=3)
btn_medium = Button(difficulty_frame, text="Sedang", command=qz_md_starter).pack(pady=3)
btn_hard = Button(difficulty_frame, text="Susah", command=qz_hrd_starter).pack(pady=3)
#Exit Button
btn_exit = Button(menu, text="KELUAR", command=menu.destroy).pack(pady=5)
I'm kind of new to coding, I decide that I want to learn python. Hoping for your response, thx.