Auto Login with Python

Auto Login with Python

So today we will learn how to auto login in a tab using Python.

So, let’s first see the code, and then we will understand the code through comments.


Code


# importing the tkinter module
from tkinter import *

# defining a function
def fun():
    # defining autologin function and upon calling this function        
    # values for username and password will be autowritten
    def autologin():
        # setting username as coding community
        username.set("coding community")
        # setting secret password
        password.set("****************")

    # initializing tkinter
    login_screen = Tk()

    # setting gui title
    login_screen.title("Auto login with python")
    # setting gui geometry
    login_screen.geometry("300x250")

    # creating a text label widget and packing it
    Label(login_screen, text="Please enter login details").pack()

    # creating a text label widget and packing it
    Label(login_screen, text="Username").pack()
    # declaring a string type variable to store username from 
    # entry widget
    username = StringVar()

    # declaring a string type variable to store password from
    # entry widget
    password = StringVar()

    # creating a entry widget to take username 
    username_login_entry = Entry(login_screen, textvariable=username)
    # packing entry widget on gui screen
    username_login_entry.pack()

    # creating a text label widget and packing it
    l1 = Label(login_screen, text="Password").pack()

    # creating an entry widget to take password from user
    password_login_entry = Entry(login_screen, textvariable=password)

    # packing the entry widget
    password_login_entry.pack()

    # adding button to application screen to call autologin     
    # function
    Button(login_screen, text="Apply auto fill", command=autologin).pack()
    
    # adding button to applicaton screen to ask user to login
    Button(login_screen, text="Login Now", width=10, height=1).pack(pady=10)

    # running the mainloop when the code is ready
    login_screen.mainloop()

fun()

Thanks for visiting the site


Keep in touch with our site for more amazing material like this


Also read:


  • Make money with Python in 2022
    Did you know that data science was the fifth most common job on LinkedIn in 2017? Did you know that the demand for Python programmers is expected to grow by 19% from 2020-2021? Did you know that Python is one of the fastest-growing programming languages, and it will likely continue to expand as its adoption…
  • Top 15 Python Libraries For Data Science in 2022
    Introduction In this informative article, we look at the most important Python Libraries For Data Science and explain how their distinct features may help you develop your data science knowledge. Python has a rich data science library environment. It’s almost impossible to cover everything in a single article. As a consequence, we’ve compiled a list…
  • Top 15 Python Libraries For Machine Learning in 2022
    Introduction  In today’s digital environment, artificial intelligence (AI) and machine learning (ML) are getting more and more popular. Because of their growing popularity, machine learning technologies and algorithms should be mastered by IT workers. Specifically, Python machine learning libraries are what we are investigating today. We give individuals a head start on the new year…
  • File Explorer in Python using Tkinter
    Introduction Welcome to copyassignment.com. In this tutorial, we are going to learn File Explorer in Python using the Tkinter module. What is basically a file explorer? A file explorer is nothing but an application that is used to manage certain files and folders on your device where we can open, edit, copy, delete and move…
  • Drawing Application in Python Tkinter
    Introduction In this article, we will design and construct a basic Drawing Application in Python Tkinter GUI, where we can simply draw something on the canvas using a pencil and erase with an eraser, as well as the ability to change the thickness of a pencil and eraser. We may also modify the canvas’s background…
Share:
Avatar of Harry

Author: Harry

Hello friends, thanks for visiting my website. I am a Python programmer. I, with some other members, write blogs on this website based on Python and Programming. We are still in the growing phase that's why the website design is not so good and there are many other things that need to be corrected in this website but I hope all these things will happen someday. But, till then we will not stop ourselves from uploading more amazing articles. If you want to join us or have any queries, you can mail me at admin@copyassignment.com Thank you

4 thoughts on “Auto Login with Python

  1. i ran the below code,but selecting add info did not populate the data in the field which i set. Not able to find the issue in my code

    from tkinter import *

    def fun():
    def info():
    user_name.set(“user name”)
    password.set(“*****”)
    root = Tk()

    root.geometry(“400×300”)

    root.title(“Welcome to login screen”)

    Label(root, text=”login Page”).pack(pady=10)

    Label(root, text=”User Name”).pack()

    user_name = StringVar()
    password = StringVar()

    user_name_entry = Entry(root, textvariable=”user_name”)

    user_name_entry.pack()

    Label(root, text=”Password”).pack()

    password_entry = Entry(root, textvariable=”password”)

    password_entry.pack()

    Button(root, text=”Add Info”, command=info).pack(pady=10)

    Button(root, text=”Clear”).pack(pady=10)

    root.mainloop()

    fun()

    Please let me know the error i did.

  2. import os
    import tkinter
    from tkinter import *

    def delete2():
    screen3.destroy()

    def delete3():
    screen4.destroy()

    def delete4():
    screen5.destroy()

    def login_sucess():
    global screen3
    screen3 = Toplevel(screen)
    screen3.title(“Success”)
    screen3.geometry(“150×100”)
    Label(screen3, text = “Login Sucess”).pack()
    Button(screen3, text = “OK”, command =delete2).pack()

    def password_not_recognised():
    global screen4
    screen4 = Toplevel(screen)
    screen4.title(“Success”)
    screen4.geometry(“150×100”)
    Label(screen4, text = “Password Error”).pack()
    Button(screen4, text = “OK”, command =delete3).pack()

    def user_not_found():
    global screen5
    screen5 = Toplevel(screen)
    screen5.title(“Success”)
    screen5.geometry(“150×100”)
    Label(screen5, text = “User Not Found”).pack()
    Button(screen5, text = “OK”, command =delete4).pack()

    def register_user():
    print(“working”)

    username_info = username.get()
    password_info = password.get()

    file=open(username_info, “w”)
    file.write(username_info+”\n”)
    file.write(password_info)
    file.close()

    username_entry.delete(0, END)
    password_entry.delete(0, END)

    Label(screen1, text = “Registration Sucess”, fg = “green” ,font = (“calibri”, 11)).pack()

    def login_verify():

    username1 = username_verify.get()
    password1 = password_verify.get()
    username_entry1.delete(0, END)
    password_entry1.delete(0, END)

    list_of_files = os.listdir()
    if username1 in list_of_files:
    file1 = open(username1, “r”)
    verify = file1.read().splitlines()
    if password1 in verify:
    login_sucess()
    else:
    password_not_recognised()

    else:
    user_not_found()

    def register():
    global screen1
    screen1 = Toplevel(screen)
    screen1.title(“Register”)
    screen1.geometry(“300×250”)

    global username
    global password
    global username_entry
    global password_entry
    username = StringVar()
    password = StringVar()

    Label(screen1, text = “Please enter details below”).pack()
    Label(screen1, text = “”).pack()
    Label(screen1, text = “Username * “).pack()

    username_entry = Entry(screen1, textvariable = username)
    username_entry.pack()
    Label(screen1, text = “Password * “).pack()
    password_entry = Entry(screen1, textvariable = password)
    password_entry.pack()
    Label(screen1, text = “”).pack()
    Button(screen1, text = “Register”, width = 10, height = 1, command = register_user).pack()

    def login():
    global screen2
    screen2 = Toplevel(screen)
    screen2.title(“Login”)
    screen2.geometry(“300×250”)
    Label(screen2, text = “Please enter details below to login”).pack()
    Label(screen2, text = “”).pack()

    global username_verify
    global password_verify

    username_verify = StringVar()
    password_verify = StringVar()

    global username_entry1
    global password_entry1

    Label(screen2, text = “Username * “).pack()
    username_entry1 = Entry(screen2, textvariable = username_verify)
    username_entry1.pack()
    Label(screen2, text = “”).pack()
    Label(screen2, text = “Password * “).pack()
    password_entry1 = Entry(screen2, textvariable = password_verify)
    password_entry1.pack()
    Label(screen2, text = “”).pack()
    Button(screen2, text = “Login”, width = 10, height = 1, command = login_verify).pack()

    def main_screen():
    global screen
    screen = Tk()
    screen.geometry(“300×250”)
    screen.title(“Notes 1.0”)
    Label(text = “Notes 1.0”, bg = “grey”, width = “300”, height = “2”, font = (“Calibri”, 13)).pack()
    Label(text = “”).pack()
    Button(text = “Login”, height = “2”, width = “30”, command = login).pack()
    Label(text = “”).pack()
    Button(text = “Register”,height = “2”, width = “30”, command = register).pack()

    screen.mainloop()

    main_screen()

Comments are closed.