Python Forum
how do i save my all my edits performed in adminpanel with one button
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how do i save my all my edits performed in adminpanel with one button
#1
first of all i am new to tkinter i tried to understand as much as i could and tried making the program accordingly now here is my current status
i have 3 files -userfile,json(database) and admin file 
i am working on admin file right now which is suppose to help me make changes performed in admin file directly to the json file 
i have created a finished button in which i need to add a function that would save all the changes made in the admin panel file directly to the database json file but idk how exactly to do that which function and how will it exactly work with that function 

ps- again i am new to tkinter so please bare me help would be great 


here is the link to my repository can anyone help me out ?

https://github.com/rashi-kp/tkinterquiz
Reply
#2
Quote:
def finished():
    new_list = []
    for i in range(len(user_data)):
        new_list.append({}) # add a empty dictionary to the new list
        new_list[i]['answer'] = user_data[i]['answer'].get()
        # add question data and options data the same way

    #save the new data
    with open('db.json', 'w') as f:
        json.dump(new_list, f, indent=2)

Looks like you already do it.  ...except that you're saving the new file with a different name than what you're reading.  ie: everywhere else, you call it "database.json", but when you're writing changes, you create a new file called "db.json" instead.
Reply
#3
(Apr-26-2017, 05:38 AM)nilamo Wrote:
Quote:
def finished():
    new_list = []
    for i in range(len(user_data)):
        new_list.append({}) # add a empty dictionary to the new list
        new_list[i]['answer'] = user_data[i]['answer'].get()
        # add question data and options data the same way

    #save the new data
    with open('db.json', 'w') as f:
        json.dump(new_list, f, indent=2)

Looks like you already do it.  ...except that you're saving the new file with a different name than what you're reading.  ie: everywhere else, you call it "database.json", but when you're writing changes, you create a new file called "db.json" instead.

yes i have changed the named to db.json because its corrupting the data store in json file called database.json so i have changed it to db.json to avoid that for time being
Reply
#4
I'm confused then. The issue is that changes aren't getting saved back to the original json file. But you're purposefully not saving changes back to that file.
...so what's the problem?
Reply
#5
(Apr-28-2017, 09:27 PM)nilamo Wrote: I'm confused then.  The issue is that changes aren't getting saved back to the original json file.  But you're purposefully not saving changes back to that file.
...so what's the problem?

just replace that code with this once and try running the file again u'll notice what i am exactly trying to tell

with open('database.json', 'w') as f:
        json.dump(new_list, f, indent=2)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] [split] I want to add a code to the "Save" button to save the data entered LOO 1 1,959 Jan-23-2023, 05:31 PM
Last Post: deanhystad
  [PySimpleGui] How to alter mouse click button of a standard submit button? skyerosebud 3 5,013 Jul-21-2019, 06:02 PM
Last Post: FullOfHelp
  Save image from Clipboard Linux / save Pixbuf format M_Schneider 1 2,843 May-04-2018, 04:38 PM
Last Post: woooee

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020