Thursday, 11 September, 2025г.
russian english deutsch french spanish portuguese czech greek georgian chinese japanese korean indonesian turkish thai uzbek

пример: покупка автомобиля в Запорожье

 

Python and Tkinter - Listbox, how to add and delete items

Python and Tkinter - Listbox, how to add and delete itemsУ вашего броузера проблема в совместимости с HTML5
How to add items and how to delete them into a listbox using Python and Tkitner link: https://pythonprogramming.altervista.org/tkinter-12-listbox/ The code with chance to save data import tkinter as tk root = tk.Tk() root.title("List App") root.geometry("400x400") def retrievedata(): global list_data list_data = [] try: with open("save.txt", "r", encoding="utf-8") as file: for f in file: listbox.insert(tk.END, f.strip()) list_data.append(f.strip()) print(list_data) except: pass def clicked(): global list_data listbox.insert(tk.END, content.get()) list_data.append(content.get()) def delete(): global list_data listbox.delete(0, tk.END) list_data = [] def delete_selected(): global list_data selected = listbox.get(listbox.curselection()) listbox.delete(tk.ANCHOR) #index = list_data[list_data.index(selected)] #print(index) list_data.pop(list_data.index(selected)) def quit(): global root with open("save.txt", "w", encoding="utf-8") as file: for d in list_data: file.write(d + "\n") root.destroy() # LISTBOX content = tk.StringVar() entry = tk.Entry(root, textvariable=content) entry.pack() button = tk.Button(root, text="Add Item", command=clicked) button.pack() button_delete = tk.Button(text="Delete", command=delete) button_delete.pack() button_delete_selected = tk.Button(text="Delete Selected", command=delete_selected) button_delete_selected.pack() listbox = tk.Listbox(root) listbox.pack() bquit = tk.Button(root, text="Quit and save", command=quit) bquit.pack() retrievedata() root.mainloop()
Мой аккаунт