J'ai un petit bout de code qui fait appel a un fichier txt. A l'ouverture de la fenetre je souhaiterais qu'il le lise et affiche la valeur dans l'entry. Débutant en python et tkinter j'avoue qu'après avoir retourné le probleme dans tous les sens je seche.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
#!/usr/bin/python
# -*- coding: cp1252 -*-
 
from Tkinter import *
import os
import csv
 
def ok():
    global fichier
    fichier = open('Relation.txt', 'w') 
    fichier.write(Relation.get())
    fichier.close()
 
application = Tk()
application.title("Relation")
fichier = StringVar()
barreEtat = Label(application, text="Ici bientôt un texte d'aide", bd=1, relief=GROOVE, anchor=W)
barreEtat.pack(side=BOTTOM, fill=X)
 
panneauSup = Frame(application, width=1000, height = 20, relief = FLAT, bg="#FFFF99")
label1=Label(panneauSup, text='   RELATION   :  ', font = ('arial', '14'), bg="#FFFF99", width=10)
label1.grid(row=0,column=0)
Relation = Entry(panneauSup, textvariable=fichier, width=30)
Relation.grid(row=0, column=1, sticky=W)
panneauSup.pack(side=TOP, fill=BOTH, expand=False)
bOk=Button(panneauSup, text='OK', fg='brown')
bOk.grid(row=0,column=2,sticky=E)
bOk.config(state=NORMAL, relief=RAISED, command=ok)
application.mainloop()