Ecriture en début de fichier commandée par un bouton tkinter
Bonjour à tous,
Je voudrais créer un programme qui écrient au début d'un fichier txt lorsque je clic sur un bouton tkinter mais j'ai des message d'erreur... Quelqu'un pourrait me venir en aide je bloque complètement! :)
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| from tkinter import *
import os
fenetre = Tk()
monfichier=open("listedesconsignesAGV.txt","w")
monfichier2=open("listedesconsignesAGV.txt","r")
def ff2(bt,fichier):
num=bt.cget("text")
text=fichier.read()
textInsert = "doTask goto"+ "\t"+str(num)+"\n"
fileW = open("listedesconsignesAGV2.txt", "w")
fileW.write(textInsert + text)
fileW.close()
os.remove("listedesconsignesAGV.txt")
os.rename("listedesconsignesAGV2.txt", "listedesconsignesAGV.txt")
Frame1 = Frame(fenetre, borderwidth=2, relief=GROOVE)
Frame1.pack()
bouton6=Button(Frame1, text="Manquant VS", font="Arial 20", bg="gray",relief=RAISED)
bouton6.config(command=lambda bt=bouton6: ff2(bt, monfichier2))
bouton6.pack()
fenetre.mainloop() |