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 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
| import tkinter as tk
import os
import glob
from os import path
from functools import partial
import numpy as np
import matplotlib.pyplot as plt
from tkinter.messagebox import *
from tkinter.filedialog import *
import tkinter.ttk as TTK
class interface(tk.Tk):
################################## Constructeur ########################################
def __init__(self, width, height):
## Paramètres de la classe interface
self.width = width
self.height = height
self.taille = str(self.width) + "x" + str(self.height)
self.ligne = 50
self.colonne = 350
#self.directorylist = []
self.listbox = ""
self.filename = []
## Creation de la fenetre
tk.Tk.__init__(self)
self.title('Post-processing')
self.geometry(self.taille)
self.initialisation()
#################### Fin constructeur ########################
############################## Definitions des fonctions utilisées ###################################
######### Initialisation de la fenetre ########################
def initialisation(self):
## Creation des menus
menubar = tk.Menu(self)
self.config(menu = menubar)
menufichier = tk.Menu(menubar, tearoff = 0)
menubar.add_cascade(label = "Fichier", menu = menufichier)
menulaser = tk.Menu(menubar,tearoff=0)
menubar.add_cascade(label= "Laser", menu=menulaser)
menubehavior = tk.Menu(menubar,tearoff=0)
menubar.add_cascade(label= "Behavior", menu=menubehavior)
menufichier.add_command(label = "Nouveau", command = self.nouveau)
menufichier.add_separator()
menufichier.add_command(label = "Quitter", command = self.destroy)
menulaser.add_cascade(label = "Mean")
menubehavior.add_cascade(label = "Mean")
## Creation des quatre espaces
self.f1 = tk.Frame(self, width=int(self.width/6), height=int(self.height/3), bg = 'yellow')
self.f2 = tk.Frame(self, width=int(self.width/6), height=int(self.height/3), bg='blue')
self.f3 = tk.Frame(self, width=int(4*self.width/6), height=int(self.height/3), bg='green')
self.f4 = tk.Frame(self, width=self.width, height=2*int(self.height/3), bg='grey')
self.canvasf2=Canvas(self.f2,width=int(self.width/6), height=int(self.height/3),scrollregion=(0,0,1000,1000))
## Positionnement des espaces
self.f1.grid(row = 0, column = 0)
self.f1.grid_propagate(0)
self.f2.grid(row = 0, column = 1)
self.f2.grid_propagate(0)
self.f3.grid(row = 0, column = 2)
self.f3.grid_propagate(0)
self.f4.grid(row=1, column = 0, columnspan = 3)
self.f4.grid_propagate(0)
## Creation de la scrollbar du F2
self.vbar2=tk.Scrollbar(self.f2,orient=VERTICAL)
self.vbar2.pack(side=RIGHT,fill=Y)
self.vbar2.config(command=self.canvasf2.yview)
self.canvasf2.config(yscrollcommand=self.vbar2.set)
self.canvasf2.pack(side=LEFT,expand=True,fill=BOTH)
self.remplirf1(self.listbox)
## Test ##
bouton = Button(self.f2, text = "test", command = self.testbouton).grid()
def testbouton(self):
label = Label(self.f2, text = "ca marche").grid()
######################### Fin initialisation ###########################
######################### Remise à zero de la page ######
def nouveau(self):
self.initialisation()
############################################################
######################### Listbox en fonction de data #############
def remplirf1(self, listbox):
directorylist = os.listdir("Data")
choices = tk.Variable(self.f1, directorylist)
self.listbox = tk.Listbox(self.f1, listvariable=choices, selectmode="multiple")
self.listbox.insert('end')
self.listbox.grid()
button = tk.Button(self.f1, text='Ok', command=partial(self.show_selection, choices, listbox))
button.grid()
self.filename = ['0' for i in range(len(directorylist))]
def show_selection(self, label, choices, listbox):
choices = choices.get()
i=0
for index in listbox.curselection():
self.canvasf2.create_window(self.colonne,self.ligne, window = Button(canvasf2, text = choices[index], command = self.fermeture(index)))
i+=1
self.ligne+=50
def fermeture(self,index):
def testfile(self):
self.filename[index] = askopenfilename(initialdir = path.join("Data",self.directorylist[index],"METADATA"),title="Ouvrir votre document",filetypes=[('txt files','.txt')])
canvas.create_text(self.colonne,self.ligne,text = self.filename[index])
self.ligne+=20
#metadata(filename[index], index)
print(self.filename)
return(self.testfile)
if __name__ == "__main__":
app = interface(1440,900)
app.mainloop() |
Partager