Update_btn.pack(side=RIGHT,ipadx=30, pady=10) Update_btn = tk.Button(frame2, text="Update", command=update_record) selected = json_tree.focus()ĭata = json_em(selected, text='', values=(str(logo_lb.get()),str(name_lb.get()),str(lastname_lb.get()),str(something_lb.get()))) Me selecciona el item, me lo modifica en el treeview pero en el json me borra lo previo. Using something that has the same structure as the object returned by json.load() would be a good idea. You cannot dump() a TreeView, so you'll need to collect the TreeView items in Python object that can be dumped. Quote:You use json.dump(python_object) to write a json file. Nice, now I understand the difference and I was able to apply it. You use json.dump(python_object) to write a json file. These work and when I modify them in the tree they are updated, but how would I call the json in this situation to update the values and not to add them as another object in the list? # Automatically closes the file when you exit the code block (de-indent) Quote:Now I have another question, I have some entries to be able to modify the data obtained from the treeview. with open('personal.json', 'r') as file: # opens the file for readingĭata = json.load(file) # reads the json file and returns python obects Leaving files open is a bad practice, and using a context manager makes it really easy to make sure you always close files. In addition to using json.load(file_obj) instead of json.loads(str_obj), my example used a context manager to automatically close the json file when we were done using it. No need to call read() to get the file contents. The json.load() call reads the dictionary and creates python objects. That works, but why read the file and then convert when you can do it with one call. Then it loads() the str object to create python objects. In your earlier post you said this worked: f = open ('personal.json', "r")ĭata = json.loads(f.read())This code reads the entire file and returns a str object. Json_em(selected, text='', values=(logo_lb.get(),nombre_lb.get(),tenantid_lb.get(),aplicationid_lb.get(),secretid_lb.get(),token_lb.get(),periodicidad_lb.get(),region_combobox2.get())) Region_combobox2.insert(0,values)with this I save the updates, which are only visualized in the tree but as it is not connected with the json, the changes are not made in the file. With this I select the object in the tree def select_record(): Now I have another question, I have some entries to be able to modify the data obtained from the treeview. ThanksĮrror:AttributeError: 'str' object has no attribute 'read'with loads it shows me the json data in the treeview. Json_tree.insert(parent='', index='end', iid=0, text="", values=(weapon,weapon,weapon,weapon,weapon,weapon,weapon,weapon))I would be very grateful if someone can exemplify or guide me on what I am doing wrong. If I try this way, that I saw in another code, nothing appears in the treeview. Json_tree.insert(parent='', index="end", iid=count, text="", values=(record, record,record,record,record,record,record,record)) I tried adding the json in this way, but it only lists the first object in the list. What I'm looking for is that when I enter the corresponding tab, it displays the data loaded in a json, through the treeview. If I increase the number of data lines I have less empty lines, I think there is a minimum number of lines and if the data lines are less than minimum the listbox shows white lines.Hi, I'm using python for a short time and I'm getting a little complicated. It works but if there are few lines I have some empty lines at the end. ee = ttk.Treeview(columns=lb_header, show="headings") I have the following code to build a listbox with Treeview widget.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |