Last active
January 13, 2022 18:54
-
-
Save bnsheehy/006fc23e71c55312f71f342444634a7f to your computer and use it in GitHub Desktop.
Python Open Local Drive Window - Tkinter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Import the Tkinter and JSON libraries | |
from tkinter import * | |
from tkinter import filedialog | |
from tkinter import Tk | |
import json | |
# Quickly get rid of the root window popup | |
root = Tk() | |
root.withdraw() | |
# Use Filedialog.askopenfilename to open a dialog window where you can select your credentials file. | |
filepath = filedialog.askopenfilename() | |
file = open(filepath, 'r') | |
# Open the credentials file with json.load | |
credentials = json.load(file) | |
file.close() | |
# Do something with credentials, or | |
print(credentials) | |
# Use Python list comprehension to save each credential to a separate variable. | |
username = credentials['data_api_username'] | |
api_key = credentials['data_api_key'] | |
aws_access_key = credentials['aws_access_key'] | |
aws_secret_key = credentials['aws_secret_key'] | |
# # Or use this method for saving data to variables: | |
# username = list(credentials.values())[0] | |
# api_key = list(credentials.values())[1] | |
# aws_access_key = list(credentials.values())[2] | |
# aws_secret_key = list(credentials.values())[3] | |
print("username:", username) | |
print("api key:", api_key) | |
print("aws key:", aws_access_key) | |
print("aws secret key:", aws_secret_key) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment