|
1 | 1 | from tkinter import * |
| 2 | +from tkinter import ttk |
2 | 3 | import tkinter as tk |
3 | 4 | from PIL import ImageTk, Image |
4 | 5 | from tkinter import messagebox |
5 | 6 | import smtplib |
6 | 7 | from tkinter.scrolledtext import ScrolledText |
7 | 8 |
|
8 | | - |
9 | 9 | root = tk.Tk() |
10 | 10 |
|
| 11 | +# Custom styles for hover effects |
| 12 | +style = ttk.Style() |
| 13 | +style.theme_use('clam') # You can choose a different theme if needed |
11 | 14 |
|
| 15 | +style.map("C.TButton", |
| 16 | + foreground=[('pressed', 'black'), ('active', 'blue')], |
| 17 | + background=[('pressed', '!disabled', 'gray'), ('active', 'white')] |
| 18 | +) |
12 | 19 |
|
| 20 | +style.map("L.TButton", |
| 21 | + foreground=[('pressed', 'black'), ('active', 'blue')], |
| 22 | + background=[('pressed', '!disabled', 'gray'), ('active', 'orange')] |
| 23 | +) |
13 | 24 |
|
14 | | -def Login(): |
15 | | - e = email.get() |
16 | | - p = password.get() |
17 | | - |
18 | | - if '@gmail.com' not in e or e == "" : |
19 | | - messagebox.showerror('Login error',"PLease Write the Valid Email") |
20 | | - elif p == "": |
21 | | - messagebox.showerror('Login error'," Password Shouldn't be Empty") |
22 | | - |
23 | | - else: |
24 | | - try: |
25 | | - |
26 | | - s = smtplib.SMTP('smtp.gmail.com', 587) |
27 | | - s.starttls() |
28 | | - s.login(e,p) #attempt to log into smtp server |
29 | | - messagebox.showinfo("Login Success","You have Logged to Gmail Successfully") |
30 | | - |
31 | | - |
32 | | - |
33 | | - |
34 | | - root = tk.Tk() |
35 | | - root.geometry('500x400') |
36 | | - |
37 | | - def Logout(): |
38 | | - s.quit() |
39 | | - root.destroy() |
40 | | - |
41 | | - |
42 | | - |
43 | | - header1 = Label(root,bg="orange",width=300,height=2) |
44 | | - header1.place(x=0,y=0) |
45 | | - |
46 | | - h2 = Label(root,text="Email Sender",bg="orange",fg="black",font= ('verdana',13,'bold')) |
47 | | - h2.place(x=175,y=5) |
48 | | - |
49 | | - logout = Button(root,text="Logout",padx=20,bg="orange",relief=RIDGE,borderwidth=1,font= ('verdana',10,'bold'),cursor="hand2",command=Logout) |
50 | | - logout.place(x=390,y=38) |
51 | | - |
52 | | - |
53 | | - |
54 | | - r = Label(root,text="Recipetent Email Address",font= ('verdana',10,'bold')) |
55 | | - r.place(x=130,y=130) |
56 | | - recipetent = Entry(root,width=30,relief=RIDGE,borderwidth=3) |
57 | | - recipetent.place(x=130,y=150) |
58 | | - |
59 | | - |
60 | | - |
61 | | - st = Label(root,text="Subject",font= ('verdana',10,'bold')) |
62 | | - st.place(x=130,y=190) |
63 | | - subject = Entry(root,width=30,relief=RIDGE,borderwidth=3) |
64 | | - subject.place(x=130,y=210) |
65 | | - |
66 | | - m = Label(root,text="Message",font= ('verdana',10,'bold')) |
67 | | - m.place(x=130,y=250) |
68 | | - |
69 | | - message = ScrolledText(root,width=40,height=5,relief=RIDGE,borderwidth=3) |
70 | | - message.place(x=130,y=270) |
71 | | - |
72 | | - |
73 | | - |
74 | | - def Send(): |
75 | | - r = recipetent.get() |
76 | | - st = subject.get() |
77 | | - m = message.get('1.0',END) |
78 | | - |
79 | | - if '@gmail.com' not in r or r == "": |
80 | | - messagebox.showerror('Sending Mail error',"Please Write the Valid Email") |
81 | | - elif m == "": |
82 | | - messagebox.showerror('Sending Mail error',"Message shouldn't be Empty") |
83 | | - |
84 | | - else: |
85 | | - s.sendmail(r,e,f'Subject :{st}\n\n {m}') |
86 | | - messagebox.showinfo("Success","Your Message has been send successfully") |
87 | | - |
88 | | - |
89 | | - |
90 | | - send = Button(root,text="Send",padx=30,relief=RIDGE,borderwidth=1,bg="orange",font= ('verdana',10,'bold'),cursor="hand2",command=Send) |
91 | | - send.place(x=350,y=360) |
92 | | - root.mainloop() |
93 | | - |
94 | | - |
95 | | - |
96 | | - |
97 | | - |
98 | | - |
99 | | - |
100 | | - |
101 | | - |
102 | | - except: |
103 | | - messagebox.showerror('Login error',"Failed to Login, Either Your Email or Password is Wrong nor You did Enable less secure Apps in gmail Setting") |
104 | | - |
105 | | - |
106 | | - |
107 | | - |
108 | | - |
| 25 | +def on_enter(event): |
| 26 | + event.widget.config(bg="orange") |
109 | 27 |
|
| 28 | +def on_leave(event): |
| 29 | + event.widget.config(bg="white") |
110 | 30 |
|
| 31 | +def Login(): |
| 32 | + e = email.get() |
| 33 | + p = password.get() |
| 34 | + |
| 35 | + if '@gmail.com' not in e or e == "": |
| 36 | + messagebox.showerror('Login error',"Please write a valid email") |
| 37 | + elif p == "": |
| 38 | + messagebox.showerror('Login error',"Password shouldn't be empty") |
| 39 | + else: |
| 40 | + try: |
| 41 | + s = smtplib.SMTP('smtp.gmail.com', 587) |
| 42 | + s.starttls() |
| 43 | + s.login(e,p) |
| 44 | + messagebox.showinfo("Login Success","You have logged into Gmail successfully") |
| 45 | + root.withdraw() # Hide login window |
| 46 | + |
| 47 | + # Create the main window |
| 48 | + main_window = tk.Toplevel() |
| 49 | + main_window.geometry('500x400') |
| 50 | + main_window.title('Email Sender') |
| 51 | + |
| 52 | + def Logout(): |
| 53 | + s.quit() |
| 54 | + main_window.destroy() |
| 55 | + |
| 56 | + header1 = Label(main_window, bg="orange", width=300, height=2) |
| 57 | + header1.place(x=0, y=0) |
| 58 | + |
| 59 | + h2 = Label(main_window, text="Email Sender", bg="orange", fg="black", font=('verdana', 13, 'bold')) |
| 60 | + h2.place(x=175, y=5) |
| 61 | + |
| 62 | + logout = ttk.Button(main_window, text="Logout", style="C.TButton", width=10, command=Logout) |
| 63 | + logout.place(x=390, y=38) |
| 64 | + |
| 65 | + r = Label(main_window, text="Recipient Email Address", font=('verdana', 10, 'bold')) |
| 66 | + r.place(x=130, y=130) |
| 67 | + recipient = Entry(main_window, width=30, relief=RIDGE, borderwidth=3) |
| 68 | + recipient.place(x=130, y=150) |
| 69 | + |
| 70 | + st = Label(main_window, text="Subject", font=('verdana', 10, 'bold')) |
| 71 | + st.place(x=130, y=190) |
| 72 | + subject = Entry(main_window, width=30, relief=RIDGE, borderwidth=3) |
| 73 | + subject.place(x=130, y=210) |
| 74 | + |
| 75 | + m = Label(main_window, text="Message", font=('verdana', 10, 'bold')) |
| 76 | + m.place(x=130, y=250) |
| 77 | + |
| 78 | + message = ScrolledText(main_window, width=40, height=5, relief=RIDGE, borderwidth=3) |
| 79 | + message.place(x=130, y=270) |
| 80 | + |
| 81 | + def Send(): |
| 82 | + r = recipient.get() |
| 83 | + st = subject.get() |
| 84 | + m = message.get('1.0', END) |
| 85 | + |
| 86 | + if '@gmail.com' not in r or r == "": |
| 87 | + messagebox.showerror('Sending Mail error', "Please write a valid email") |
| 88 | + elif m == "": |
| 89 | + messagebox.showerror('Sending Mail error', "Message shouldn't be empty") |
| 90 | + else: |
| 91 | + s.sendmail(r, e, f'Subject :{st}\n\n {m}') |
| 92 | + messagebox.showinfo("Success", "Your message has been sent successfully") |
| 93 | + |
| 94 | + send = ttk.Button(main_window, text="Send", style="C.TButton", width=10, command=Send) |
| 95 | + send.place(x=350, y=360) |
| 96 | + |
| 97 | + main_window.mainloop() |
| 98 | + |
| 99 | + except: |
| 100 | + messagebox.showerror('Login error', "Failed to login. Check your email or password.") |
111 | 101 |
|
112 | 102 | root.title('Email Sender') |
113 | 103 | root.geometry('400x300') |
114 | 104 | root.maxsize(400,300) |
115 | 105 | root.minsize(400,300) |
116 | 106 |
|
117 | | -header = Label(root,bg="orange",width=300,height=2) |
118 | | -header.place(x=0,y=0) |
| 107 | +header = Label(root, bg="orange", width=300, height=2) |
| 108 | +header.place(x=0, y=0) |
119 | 109 |
|
120 | | -h1 = Label(root,text="Email Sender",bg="orange",fg="black",font= ('verdana',13,'bold')) |
121 | | -h1.place(x=135,y=5) |
| 110 | +h1 = Label(root, text="Email Sender", bg="orange", fg="black", font=('verdana', 13, 'bold')) |
| 111 | +h1.place(x=135, y=5) |
122 | 112 |
|
123 | 113 | img = ImageTk.PhotoImage(Image.open('gmail.png')) |
124 | 114 |
|
125 | | -logo = Label(root,image=img,borderwidth=0) |
126 | | -logo.place(x=150,y=38) |
127 | | - |
128 | | - |
129 | | -e = Label(root,text="Email Address",font= ('verdana',10,'bold')) |
130 | | -e.place(x=100,y=130) |
131 | | -email = Entry(root,width=30,relief=RIDGE,borderwidth=3) |
132 | | -email.place(x=100,y=150) |
133 | | - |
134 | | - |
135 | | - |
136 | | -p = Label(root,text="Password",font= ('verdana',10,'bold')) |
137 | | -p.place(x=100,y=190) |
138 | | -password = Entry(root,width=30,relief=RIDGE,borderwidth=3) |
139 | | -password.place(x=100,y=210) |
140 | | - |
141 | | - |
142 | | -login = Button(root,text="Login",padx=30,bg="orange",relief=RIDGE,borderwidth=1,font= ('verdana',10,'bold'),cursor="hand2",command=Login) |
143 | | -login.place(x=135,y=240) |
144 | | - |
145 | | - |
146 | | - |
147 | | - |
148 | | - |
| 115 | +logo = Label(root, image=img, borderwidth=0) |
| 116 | +logo.place(x=150, y=38) |
| 117 | + |
| 118 | +e = Label(root, text="Email Address", font=('verdana', 10, 'bold')) |
| 119 | +e.place(x=100, y=130) |
| 120 | +email = Entry(root, width=30, relief=RIDGE, borderwidth=3, font=('Arial', 10)) # Changed font here |
| 121 | +email.place(x=100, y=150) |
| 122 | +email.bind("<Enter>", on_enter) |
| 123 | +email.bind("<Leave>", on_leave) |
| 124 | + |
| 125 | +p = Label(root, text="Password", font=('verdana', 10, 'bold')) |
| 126 | +p.place(x=100, y=190) |
| 127 | +password = Entry(root, width=30, relief=RIDGE, borderwidth=3, font=('Arial', 10)) # Changed font here |
| 128 | +password.place(x=100, y=210) |
| 129 | +password.bind("<Enter>", on_enter) |
| 130 | +password.bind("<Leave>", on_leave) |
| 131 | + |
| 132 | +login = ttk.Button(root, text="Login", style="L.TButton", width=10, command=Login) # Changed style here |
| 133 | +login.place(x=145, y=240) |
149 | 134 |
|
150 | 135 | root.mainloop() |
0 commit comments