Errors on Gui code

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
1 Like

The code you posted isn’t parsing as well as modern python3 I’d describe it as code that resembles Python quite a bit but isn’t quite right. I gave it a brief effort but … lost faith in Python Tk docs when I saw that the examples for Tkinter don’t work.

If you’re looking for Python Tk GUI examples, even the docs don’t really cut it in my opinion as the docs aren’t being updated at the same pace as the language.

I’d suggest that you use PySimpleGUI over at www_pysimplegui_org (remember your towel) for a better overall experience of learning with more complete documentation and working examples. Perhaps if I find a better tkinter site with working examples I’ll share it.

1 Like

I recommend starting with these links as they will help you get a basic understanding of each.

https://pythonbasics.org/tkinter/

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.