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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
| #--- Programme qui change une coordonnée (x,y ou z) de toute une matrice ---#
from Tkinter import *
from math import *
def ok():
with open("matrice.txt") as inf:
lines = inf.readlines()
roundval = int(E4.get())
entries = [float(E1.get()), float(E2.get()), float(E3.get())]
news = ""
for line in lines:
vals = line.strip().replace('[','').replace(']','').split(',')
new = []
for i, j in zip(vals, entries):
s = float(i) + j
if roundval:
s = round(s, roundval)
new.append(s)
news = news + str(new) + '\n'
with open('matrice2.txt','w') as outf:
outf.write(news)
L4.config(text = news)
L.config(text = "Finished !")
fe=Tk()
fe.title("coordinate change")
fe.geometry('1250x1000')
L=Label(fe,text='This program allows to increase or decrease one of the coordinates (X, Y or Z) of a [X,Y,Z] matrice such as: \n [15,1.454,0.1]\n[12.1,5.2,78]\n[0.3,0,45]\n(...)\n\n Please copy your matrice in a file whose the name is matrice.txt.\nPut the file in the same directory than this program. The new matrice will be in the file named matrice2.txt.',font=('Arial',17,'bold'))
L.place(x=20,y=50)
LX=Label(fe,text='X',font=('Helvetica',15,'underline'))
LX.place(x=200,y=450)
LY=Label(fe,text='Y',font=('Helvetica',15,'underline'))
LY.place(x=200,y=550)
LZ=Label(fe,text='Z',font=('Helvetica',15,'underline'))
LZ.place(x=200,y=650)
L1=Label(fe,text='Give the value(s)',font=('Helvetica',15,'underline'))
L1.place(x=400,y=410)
E1=Entry(fe)
E1.place(x=400,y=450)
E1.insert(0,0)
E2=Entry(fe)
E2.place(x=400,y=550)
E2.insert(0,0)
E3=Entry(fe)
E3.place(x=400,y=650)
E3.insert(0,0)
L2=Label(fe,text='Contenu de matrice.txt :',font=('Helvetica',15,'underline'))
L2.place(x=1000,y=320)
with open("matrice.txt") as inf:
lines = inf.readlines()
#Canvas texte contenu matrice.txt :
w = Canvas(fe, width=500, height=250)
w.place(x=1000,y=350)
text=w.create_text(10,0,anchor='nw',text=lines)
#scrollbar :
hbar=Scrollbar(fe,orient=VERTICAL)
hbar.pack(side=RIGHT,fill=X)
hbar.config(command=w.xview)
w.config(xscrollcommand=hbar.set)
L2=Label(fe,text='Contenu de matrice2.txt :',font=('Helvetica',15,'underline'))
L2.place(x=1000,y=620)
L4=Label(fe,text='')
L4.place(x=1000,y=650)
B=Button(fe,text='OK',width=25,command=ok)
B.place(x=600,y=550)
L5=Label(fe,text='Voulez-vous arrondir ? Si oui, mettez le nombre de chiffres après la virgule que vous souhaitez faire apparaître :')
L5.place(x=0,y=320)
E4=Entry(fe)
E4.place(x=600,y=320)
fe.mainloop() |
Partager