I am making an emial client and i would like the two buttons (send mail and reset) to be next to eachother horizontally (not vertically). Thanks in advance (my email and password have been replaced with asterix's for security purposes)
Code:
from tkinter import *
import tkinter as tk
from email.message import EmailMessage
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
window=Tk()
window.title('Email Client')
window.geometry('450x370')
window.iconbitmap('D:\PYTHON\IMAGES\icon_for_email_clien_Jy16u.ico')
textbox2=Text(window,width=50,height=10,bg='light grey')
label2=Label(window,text='Message')
textbox1=Text(window,width=50,height=1,bg='light grey')
textbox3=Text(window,width=50,height=1,bg='light grey')
label4=Label(window,text='Directory of File Attachment')
label1=Label(window,text='Subject')
label3=Label(window,text='')
def email_alert(subject, body, to):
msg = EmailMessage()
msg.set_content(body)
msg['subject'] = subject
msg['to'] = to
user = "******************"
msg['from'] = user
password = "***********"
server = smtplib.SMTP("smtp.gmail.com", 587)
server.starttls()
server.login(user, password)
server.send_message(msg)
server.quit()
if __name__ == '__main__':
def Send():
gd = textbox3.get('1.0','end-1c')
dialog = textbox2.get('1.0','end-1c')
subject = textbox1.get('1.0','end-1c')
body = dialog
try:
fromaddr = "********************"
toaddr = "*******************"
msg = MIMEMultipart()
msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = subject
body = dialog
msg.attach(MIMEText(body, 'plain'))
filename = "Homework Attachment"
attachment = open(gd, "rb")
p = MIMEBase('application', 'octet-stream')
p.set_payload((attachment).read())
encoders.encode_base64(p)
p.add_header('Content-Disposition', "attachment; filename= %s" % filename)
msg.attach(p)
s = smtplib.SMTP('smtp.gmail.com', 587)
s.starttls()
s.login(fromaddr, "*************")
text = msg.as_string()
s.sendmail(fromaddr, toaddr, text)
s.quit()
except:
email_alert(subject, dialog, "************************")
def Reset():
textbox1.delete('1.0', 'end-1c')
textbox2.delete('1.0', 'end-1c')
textbox3.delete('1.0', 'end-1c')
label1.pack()
textbox1.pack()
label4.pack()
textbox3.pack()
label2.pack()
textbox2.pack()
label3.pack()
button1=Button(window,text='Send Email',width=15,height=1, command=Send)
button1.pack()
button2=Button(window,text='Reset',width=15,height=1, command=Reset)
button2.pack(pady = 10)
window.mainloop()
image:
The two buttons below (called send email and reset), i would like them to be horizontally next to eachother to make the GUI look a bit more appealing. However I am having trouble doing this and i have not found a suitable answer to my query. Any help is greatly appreciated :D