I have created two py files, one holds login GUI, the other contains the whole bunch of functions and windows which I call terminal.
I'm trying to do the following: To make a login GUI window appear first and after inputting correct credentials to have open/running the terminal (second GUI window).
However no matter what I tried I do not get the second window open after credentials. I have tried using if statement however failed, the only thing on my mind is re-doing the whole code in one file and that doesnt seems like a good idea to have that much code in one file
Login GUI:
import tkinter as tk
# from tkinter_practice import *
def username(txt_username):
if txt_username == "1":
return True
def password(txt_password):
if txt_password == "2":
return True
def ok_button(gotten_username, gotten_password):
if username(gotten_username) and password(gotten_password):
print('login success')
return True
else:
print('Incorrect Username or Password')
return False
root2 = tk.Tk()
root2.title('Login window')
root2.geometry('400x200-550-400')
root2.columnconfigure(0, weight=1)
root2.columnconfigure(1, weight=1)
root2.columnconfigure(2, weight=1)
root2.rowconfigure(0, weight=1)
root2.rowconfigure(1, weight=1)
root2.rowconfigure(2, weight=1)
lbl_username = tk.Label(root2, text='Username')
lbl_username.grid(row=1, column=0)
ent_username = tk.Entry(root2)
ent_username.grid(row=1, column=1)
lbl_password = tk.Label(root2, text='Password')
lbl_password.grid(row=2, column=0, sticky='n')
ent_password = tk.Entry(root2)
ent_password.grid(row=2, column=1, sticky='n')
btn_ok = tk.Button(root2, text='LOGIN', command=lambda: ok_button(ent_username.get(), ent_password.get()), padx=10,
pady=5)
btn_ok.grid(row=3, column=1, sticky='nw', )
btn_cancel = tk.Button(root2, text='Cancel', command=quit, padx=10, pady=5)
btn_cancel.grid(row=3, column=1, sticky='n')
root2.mainloop()
and second part of code which contains second window/GUI which I would to open after first one's credentials are True:
import tkinter as tk
from tkinter import *
# from PIL import ImageTk, Image
import webbrowser
import pytz
import datetime
import login_GUI
# from tkinter import messagebox
# Main frame/window
if login_GUI.ok_button(login_GUI.ent_username.get, login_GUI.ent_password.get):
root = tk.Tk()
root.title("Main terminal")
root.geometry("800x600-50-50")
# Here I get the icon for the left corner of bar on top
root.iconbitmap(icon)
new = 1
url = "https://www.youtube.com"
root.columnconfigure(0, weight=1)
root.columnconfigure(1, weight=1)
root.columnconfigure(2, weight=1)
root.mainloop()
Aucun commentaire:
Enregistrer un commentaire