New on python. Needs help with Google sheet - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: New on python. Needs help with Google sheet (/thread-42030.html) |
New on python. Needs help with Google sheet - jeromep - Apr-25-2024 I'm new to coding. I created the following code, but I cannot place the data entered in my Google Sheet file. JSON works. The date must go in the next 2 free cells in line 3 The time will have to go in the 2 next free cells in line 4 The registration must go in the 2 next free cells in line 1 Flight number will have to go in the 2 next free cells in line 2 routing will have to go in the next 2 free cells in line 5 I would then need when I click Visualiser les commandes pour un jour précis for the program to access the Google sheet and find the registration, flight id, time, routing information. and this is exported to a pdf file. I know it's probably a lot of code but I don't know how to do it anymore. Starting the code has already taken me a long time, and I've been trying for several hours without success See the google sheet attached import tkinter as tk from tkinter import messagebox, simpledialog import gspread from google.oauth2.service_account import Credentials from datetime import datetime import webbrowser # Charger les informations d'identification depuis le fichier JSON gc = gspread.service_account(filename=r"C:\Users\Jérôme\Downloads\XXXXXXXXXX.json") # Ouvrir la feuille de calcul et l'onglet appropriés wks = gc.open("XXXXX").worksheet("Service Order") def save_order(): compagnie_selected = selected_company.get() date = date_entry.get() heure = heure_entry.get() immatriculation = immatriculation_entry.get() numero_vol = numero_vol_entry.get() routing = routing_entry.get() # Trouver les prochaines lignes vides next_empty_row = len(wks.get_all_values()) + 1 # Insérer les données dans les prochaines lignes vides wks.update(f"A{next_empty_row}", immatriculation) wks.update(f"B{next_empty_row}", numero_vol) wks.update(f"C{next_empty_row}", date) wks.update(f"D{next_empty_row}", heure) wks.update(f"E{next_empty_row}", routing) wks.update(f"B{next_empty_row + 1}", numero_vol) # Afficher un message de confirmation messagebox.showinfo("Enregistrement", "La commande a été enregistrée avec succès !") # Fermer la fenêtre d'ajout de commande add_order_window.destroy() def add_order(root): companies = ["xxxxxx", "xxxxxxxxx", "xxxxxxx", "xxxxxxxxxx", "xxxxxxxxx"] # Variable pour stocker la compagnie sélectionnée selected_company = tk.StringVar(root) selected_company.set(companies[0]) # Définir la première compagnie comme valeur par défaut add_order_window = tk.Toplevel(root) add_order_window.title("Ajouter une nouvelle commande") # Interface utilisateur pour saisir les détails de la commande tk.Label(add_order_window, text="Pour quelle compagnie est cette commande?").grid(row=0, column=0) compagnie_combobox = tk.OptionMenu(add_order_window, selected_company, *companies) compagnie_combobox.grid(row=0, column=1) tk.Label(add_order_window, text="Date de la commande (JJ/MM/AA):").grid(row=1, column=0) date_entry = tk.Entry(add_order_window) date_entry.grid(row=1, column=1) tk.Label(add_order_window, text="Heure du vol:").grid(row=2, column=0) heure_entry = tk.Entry(add_order_window) heure_entry.grid(row=2, column=1) tk.Label(add_order_window, text="Immatriculation avion:").grid(row=3, column=0) immatriculation_entry = tk.Entry(add_order_window) immatriculation_entry.grid(row=3, column=1) tk.Label(add_order_window, text="Numéro de vol:").grid(row=4, column=0) numero_vol_entry = tk.Entry(add_order_window) numero_vol_entry.grid(row=4, column=1) tk.Label(add_order_window, text="Routing (Départ - Destination):").grid(row=5, column=0) routing_entry = tk.Entry(add_order_window) routing_entry.grid(row=5, column=1) save_button = tk.Button(add_order_window, text="Enregistrer", command=save_order) save_button.grid(row=6, columnspan=2) # Bouton pour revenir à la fenêtre principale return_button = tk.Button(add_order_window, text="Retour", command=root.deiconify) return_button.grid(row=7, columnspan=2) def main(): root = tk.Tk() root.title("Gestionnaire de commandes") def open_consult_page(): root.withdraw() # Cache la fenêtre principale consult_orders() # Ouvre la page de consultation des commandes root.deiconify() # Affiche à nouveau la fenêtre principale quand la page de consultation est fermée def open_add_order_page(): root.withdraw() add_order(root) # Passer la variable root comme paramètre root.deiconify() tk.Button(root, text="Consulter les commandes pour un jour précis", command=open_consult_page).pack(pady=10) tk.Button(root, text="Ajouter une nouvelle commande", command=open_add_order_page).pack(pady=10) tk.Button(root, text="Quitter", command=root.quit).pack(pady=10) root.mainloop() if __name__ == "__main__": main() RE: New on python. Needs help with Google sheet - deanhystad - Apr-25-2024 I cannot find where you save your worksheet. Changing the worksheet does not modify the spreadsheet file.. There may be other problems, but start by fixing this so you can see what changes you are making. |