Yash Dahake
Yash Dahake

Reputation: 1

Email Slicer Project using Tkinter but getting error? Can anyone plz help me out

print("Email Slicer")
from tkinter import *

initializing a tkinter

root = Tk()

tkinter window dimensions,title

root.geometry('400x400')
root.title("Email Slicer")
Label(root, text="").pack()
Label(root, text="Email Slicer", font = "arial 16 bold").pack()

email stringvAR

email = StringVar(root, "")

taking email input from user

Label(root, font = "arial 14", text = "Enter your email:", bg = "seashell2").place(x=90, y=100)
Entry(root, font = "arial 14", textvariable = email, bg = "seashell2").place(x=90, y=130)

user_name = StringVar(root, "Enter Email")
domain_name = StringVar(root, "Enter Email")


if "@" in email.get():
    user_name.set(email.get()[:email.get().find("@")])
    domain_name.set(email.get()[email.get().find("@") + 1:])
else:
    user_name.set("Invalid Email")
    domain_name.set("Invalid Email")

#Slicer which finds "@" in email

def Slice(str):
    if str.find("@") != -1:
        user_name.set(str[:(str.find("@"))])
        domain_name.set(str[(str.find("@")) + 1:])
    else:
        user_name.set("Enter Email")
        domain_name.set("Enter Email")

#Reset all values

def Reset():
    user_name.set("")

    domain_name.set("")

#setting default value of username and domainname

user_name.set("Enter Email")

domain_name.set("Enter Email")

#Buttons and their labels

Label(root, font = "arial 14", text = "User Name:", bg = "seashell2").place(x=90, y=180)

Entry(root, font = "arial 14 bold", textvariable = user_name, bg = "antiquewhite").place(x=90, y=220)

Label(root, font = "arial 14", text = "Domain Name:", bg = "seashell2").place(x=90, y=260)

Entry(root, font = "arial 14 bold", textvariable = domain_name).place(x=90, y=300)

Button(root, font = 'arial 14 bold', text = "Slice", bg = 'seashell4', command = 
    Slice(email.get())).place(x=100,y=340)

Button(root, font = 'arial 14 bold', text = "Reset", bg = 'seashell4', command = 
    Reset()).place(x=200,y=340)

#mainloop

root.mainloop()

Upvotes: 0

Views: 100

Answers (1)

Ritesh Khanna
Ritesh Khanna

Reputation: 146

The error was you should never have a function with parameters which used in command argument of button.

Slice and Reset functions :-

def Slice():
if email.get().find("@") != -1:
    user_name.set(email.get()[:(email.get().find("@"))])
    domain_name.set(email.get()[(email.get().find("@")) + 1:])
else:
    user_name.set("Enter Email")
    domain_name.set("Enter Email")

def Reset():
    user_name.set("")
    domain_name.set("")

Buttons and their labels

Label(root, font = "arial 14", text = "User Name:", bg = "seashell2").place(x=90, y=180)
Entry(root, font = "arial 14 bold", textvariable = user_name, bg = "antiquewhite").place(x=90, y=220)

Label(root, font = "arial 14", text = "Domain Name:", bg = "seashell2").place(x=90, y=260)
Entry(root, font = "arial 14 bold", textvariable = domain_name).place(x=90, y=300)

Button(root, font = 'arial 14 bold', text = "Slice", bg = 'seashell4', command = Slice).place(x=100,y=340)

Button(root, font = 'arial 14 bold', text = "Reset", bg = 'seashell4', command = Reset).place(x=200,y=340)

Upvotes: 1

Related Questions