Hi , i was working on a Labview problem with json files and thought about a simple standalone GUI that could be used manaully, i thought it would interesting to try it in python as im just new to it and thought it would be a good learner to try. I thought id found something that would be good , but the code given as the example seems to be different from the written code used in the animation of the example, if someone has the time and could find out why i cant get the code to work it would be greatly appreciated.
Sorry i tried to link the website but wasnt allowed ? heading was creating a JSON file with Tkinter, it was GUI that allowed you to enter data into text boxes and create a JSON file, i had hoped to use it as a primer then add drop downs and eventually try connecting a database
and the code i copied and pasted was :
import tkinter
import json
from tkinter.filedialog import asksaveasfile
window = Tk()
window.geometry('640x300')
window.title('IoT4Begineers')
name = Label(window, text="Name:")
Name = Entry(window)
age = Label(window, text="Age:")
Age = Entry(window)
role = Label(window, text="Role:")
Role = Entry(window)
submit = Button(window,text='Submit',command = check).grid(row=3, column=1)
test = 1
def writeToJSONFile(path, fileName, data):
json.dump(data, path)
path = './'
def check():
a = Name.get()
b = test * int(Age.get())
c = Role.get()
print(a)
print(b)
print(c)
data = {}
data['Name'] = a
data['Age'] = b
data['Role'] = c
files = [('JSON File', '*.json')]
fileName='IOTEDU'
filepos = asksaveasfile(filetypes = files,defaultextension = json,initialfile='IOTEDU')
writeToJSONFile(filepos, fileName, data)
name.grid(row=0, column=0)
age.grid(row=1,column=0)
role.grid(row=2,column=0)
Name.grid(row=0, column=1)
Age.grid(row=1, column=1)
Role.grid(row=2, column=1)
mainloop()
thank you