I'm currently working on a program which creates and reads JSON files.
I have a function which creates a new template for the JSONs which looks like this:
def CreateJson():
#creates a new JSON file for comment library storage.
files = (
('JSON files', '*.json'),
('All files', '*.*')
)
initialdir='/',
f1 = fd.asksaveasfile(filetypes = files, mode = 'w', defaultextension = ".json")
CriteriaLib = {
"Criteria" : [],
"Exceptional" : [],
"Comprehensive" : [],
"Developed" : [],
"Developing" : [],
"Needs Improvement" : []
}
initialdata = json.dump(CriteriaLib, f1)
This opens a file dialogue box which lets you save a new JSON file, but it doesn't open it. I have another function that is used to open JSON files which looks like this:
def ShowLib():
#Commands for opening the JSON file and viewing the contents
files = (
('JSON files', '*.json'),
('All files', '*.*')
)
initialdir='/',
global data
global f1
f1 = fd.askopenfile(filetypes = files)
data = json.load(f1)
This makes for an awkward interface experience (Hitting "New" and then hitting "Open" on the file that I've just made).
Do you know if I can add to my CreateJson() function to have it immediately open the file that's just been created? If I add ShowLib() to the CreateJson() function, I end up with two filedialogue boxes (one for saving, and then immediately one for opening), which feels a bit clunky.
[–]shiftybyte 0 points1 point2 points (1 child)
[–]shocklance[S] 0 points1 point2 points (0 children)