This is the source code to create a GUI with tkinter and upload an image to S3 by pressing a button.
import tkinter
from boto3.session import Session
session = Session(aws_access_key_id='access_key_id',
aws_secret_access_key='secret_access_key_id')
s3 = session.resource('s3')
bucket = s3.Bucket('bucket-name')
def btn_click():
bucket.upload_file('sample.png', 'sample.png')
print("uploaded !")
root = tkinter.Tk()
root.title("Image Uploader")
root.geometry("300x200")
btn = tkinter.Button(root, text='upload', command=btn_click)
btn.pack()
root.mainloop()
By executing the script, the following GUI will be displayed. By pressing the upload button, the specified image will be uploaded to S3.
Thank you for reading until the end. Let's meet again.
ps. By the way, I used the following command when converting to exe with pyinstaller.
pyinstaller .\uploader.py --onefile --noconsole --hidden-import=configparser
Recommended Posts