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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
| #!/usr/bin/env python
# -*- coding: utf-8 -*-
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)
canvas2.itemconfig(c2,text=news)
L.config(text="Finished !")
# Création de fenêtre
root = Tk()
root.rowconfigure(0, weight=1)
root.columnconfigure(0, weight=1)
root.title("coordinate change")
# Label, Entry
L=Label(root,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.grid()
L1=Label(root,text='Give the value(s)',font=('Helvetica',15,'underline'))
L1.grid(column=1)
LX=Label(root,text='X',font=('Helvetica',15,'underline'))
LX.grid(row=2)
E1=Entry(root)
E1.grid(row=2,column=1)
E1.insert(0,0)
LY=Label(root,text='Y',font=('Helvetica',15,'underline'))
LY.grid()
E2=Entry(root)
E2.grid(row=3,column=1)
E2.insert(0,0)
LZ=Label(root,text='Z',font=('Helvetica',15,'underline'))
LZ.grid()
E3=Entry(root)
E3.grid(row=4,column=1)
E3.insert(0,0)
L2=Label(root,text='Contenu de matrice.txt :',font=('Helvetica',15,'underline'))
L2.grid(row=6,column=0,columnspan=2)
with open("matrice.txt") as inf:
lines = inf.readlines()
print lines
canvas = Canvas(root, bg="white")
canvas.grid(row=7, column=0, sticky=NW+SE)
list=canvas.create_text(0,0, text=lines, font="sans 16 bold", fill="blue",anchor='nw')
# horizontal scrollbar
hbar = Scrollbar(root, orient=HORIZONTAL)
hbar.grid(row=8, column=0, sticky=NW+SE)
# vertical scrollbar
vbar = Scrollbar(root, orient=VERTICAL)
vbar.grid(row=7, column=1, sticky=W+N+S)
# connecting people...
canvas.configure(
xscrollcommand=hbar.set,
yscrollcommand=vbar.set,
scrollregion=(0, 0, 800, 600),
)
hbar.configure(command=canvas.xview)
vbar.configure(command=canvas.yview)
L2=Label(root,text='Contenu de matrice2.txt :',font=('Helvetica',15,'underline'))
L2.grid(row=6,column=2,columnspan=2)
canvas2 = Canvas(root, bg="white")
c2=canvas2.create_text(0,0, text='', font="sans 16 bold", fill="blue",anchor='nw')
canvas2.grid(row=7, column=2, sticky=NW+SE)
# horizontal scrollbar
hbar = Scrollbar(root, orient=HORIZONTAL)
hbar.grid(row=8, column=2, sticky=NW+SE)
# vertical scrollbar
vbar = Scrollbar(root, orient=VERTICAL)
vbar.grid(row=7, column=3, sticky=W+N+S)
# connecting people...
canvas2.configure(
xscrollcommand=hbar.set,
yscrollcommand=vbar.set,
scrollregion=(0, 0, 800, 600),
)
hbar.configure(command=canvas2.xview)
vbar.configure(command=canvas2.yview)
B=Button(root,text='OK',width=25,command=ok)
B.grid()
L5=Label(root,text='Voulez-vous arrondir ? Si oui, mettez le nombre de chiffres après la virgule que vous souhaitez faire apparaître :')
L5.grid(row=5)
E4=Entry(root)
E4.grid(row=5,column=1)
root.mainloop() |
Partager