I have made two separate GUI screens, one as login.py
and user_intern.py
and in user_intern.py
I have a button called login_button
, so when I click login the login.py
which contains GUI for login screen should execute and the user_intern.py
should close automatically and I didn't used class (OOP) here, I have written code fully with functions only so hereby I attached the codes and screenshots of screens.
User_intern.py
from tkinter import *
from tkinter import ttk
from PIL import Image,ImageTk
import os
import pickle
import mysql.connector as sql
from tkinter import messagebox
def login1():
host = host_entry.get()
port = port_entry.get()
username = username_entry.get()
password = password_entry.get()
database="cars"
spec=sql.connect(host=host,user=username,password=password,port=port)
if spec.is_connected():
messagebox.showinfo("Connected","Database connected Sucessfully")
else:
messagebox.showerror("Exists", "Database is already connected")
spec.close()
root = Tk()
root.geometry("1067x600")
root.configure(background="black")
root.resizable(False, False)
root.title("School Diaries")
#background image
bg = ImageTk.PhotoImage(file="files\Sublime Light1.jpg")
lbl_bg = Label(root,image=bg)
lbl_bg.place(x=0,y=0,relwidth=1,relheight=1)
#Labels
host_label = Label(root, text="Host Name ", bg="white", fg="#4f4e4d",font=("yu gothic ui", 12, "bold"))
host_label.place(x=675, y=115)
host_entry = Entry(root, highlightthickness=0, relief=FLAT, bg="white", fg="#6b6a69",font=("yu gothic ui semibold", 12))
#host_entry.insert(0, "localhost")
host_entry.place(x=687, y=139, width=145)
port_label = Label(root, text="Port ", bg="white", fg="#4f4e4d",font=("yu gothic ui", 13, "bold"))
port_label.place(x=675, y=190)
port_entry = Entry(root, highlightthickness=0, relief=FLAT, bg="white", fg="#6b6a69",font=("yu gothic ui semibold", 12))
#port_entry.insert(0, "3307")
port_entry.place(x=690, y=213, width=145)
username_label = Label(root, text="Username ", bg="white", fg="#4f4e4d",font=("yu gothic ui", 13, "bold"))
username_label.place(x=675, y=265)
username_entry = Entry(root, highlightthickness=0, relief=FLAT, bg="white", fg="#6b6a69",font=("yu gothic ui semibold", 12))
#username_entry.insert(0, "root")
username_entry.place(x=687, y=287, width=145)
password_label = Label(root, text="Password ", bg="white", fg="#4f4e4d",font=("yu gothic ui", 13, "bold"))
password_label.place(x=675, y=338)
password_entry = Entry(root, highlightthickness=0, relief=FLAT, bg="white", fg="#6b6a69",font=("yu gothic ui semibold", 12))
#password_entry.insert(0, "root")
password_entry.place(x=687, y=361, width=145)
#buttons
submit = ImageTk.PhotoImage(file='Pics\submit.png')
submit_button = Button(root, image=submit,font=("yu gothic ui", 13, "bold"), relief=FLAT, activebackground="white",borderwidth=0, background="white", cursor="hand2",command=login1)
submit_button.place(x=655, y=440)
login = ImageTk.PhotoImage(file='Pics\login.png')
login_button = Button(root, image=login,font=("yu gothic ui", 13, "bold"), relief=FLAT, activebackground="white",borderwidth=0, background="white", cursor="hand2")
login_button.place(x=785, y=442)
root.mainloop()
login.py
from tkinter import *
from tkinter import ttk
from PIL import Image,ImageTk
import os
import pickle
import mysql.connector as sql
from tkinter import messagebox
def login():
#host = user_inter.host_entry.get()
#port = user_inter.port_entry.get()
username = username_entry.get()
password = password_entry.get()
spec=sql.connect(host=host,user=username,password=password,port=port)
if spec.is_connected():
messagebox.showinfo("Connected","Database connected Sucessfully")
else:
messagebox.showerror("Exists", "Failed")
mycur=spec.cursor()
mycur.execute()
root = Tk()
root.geometry("1067x600")
root.configure(background="black")
root.resizable(False, False)
root.title("School Diaries")
#background
bg = ImageTk.PhotoImage(file="files\login.jpg")
lbl_bg = Label(root,image=bg)
lbl_bg.place(x=0,y=0,relwidth=1,relheight=1)
#Labels
login_lbl = Label(root, text="Login", bg="white", fg="#4f4e4d",font=("San Francisco", 45))
login_lbl.place(x=757,y=120)
username_label = Label(root, text="Username ", bg="white", fg="#4f4e4d",font=("yu gothic ui", 13, "bold"))
username_label.place(x=675, y=190)
username_entry = Entry(root, highlightthickness=0, relief=FLAT, bg="white", fg="#6b6a69",font=("yu gothic ui semibold", 12))
#username_entry.insert(0, "root")
username_entry.place(x=695, y=215, width=190)
password_label = Label(root, text="Password ", bg="white", fg="#4f4e4d",font=("yu gothic ui", 13, "bold"))
password_label.place(x=675, y=280)
password_entry = Entry(root, highlightthickness=0, relief=FLAT, bg="white", fg="#6b6a69",font=("yu gothic ui semibold", 12))
#password_entry.insert(0, "root")
password_entry.place(x=692, y=305, width=190)
login = ImageTk.PhotoImage(file='Pics\login.png')
login_button = Button(root, image=login,font=("yu gothic ui", 13, "bold"), relief=FLAT, activebackground="white",borderwidth=0, background="white", cursor="hand2")
login_button.place(x=770, y=390)
root.mainloop()
You can do any edits in code to get the output.