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
|
import tkinter as Tk
import tkinter.filedialog as tkFileDialog
def Affiche():
fd=tkFileDialog.askopenfilename(filetypes = [("Fichiers Tex","*.tex"),("Fichiers Python","*.py"),("Tous", "*")])
f=open(fd,"r")
texte_fichier=f.read()
f.close()
nom_fichier=str(fd)
##Remplissage du menu windows
menuWindows.add_command(label=str(fd), command=activer_fichier(str(fd)))
## Déclaration des différents widgets
f1 = Tk.Frame(root,bg ='blue', bd =5)
s1 = Tk.Scrollbar(f1, orient=Tk.VERTICAL)
texte1 = Tk.Text(f1, wrap=Tk.WORD,width =150, height =10)
## association du déplacement de la glissière des scrollbar avec la position visible dans
## le widget Text et inversement.
s1.config(command = texte1.yview)
texte1.config(yscrollcommand = s1.set)
## Placement du widget Text et des Scrollbar associés
texte1.grid(column=0, row=0)
texte1.insert(Tk.INSERT,texte_fichier)
s1.grid(column=1, row=0, sticky=Tk.S+Tk.N)
f1.pack()
def activer_fichier(nom_fichier):
print("ne rien faire pour l'instant")
## Fenêtre principale
root = Tk.Tk()
root.title="Essai de menus déroulants"
## Barre de menu parent
mainmenu = Tk.Menu(root)
## Menu fils menuExample
menuExample = Tk.Menu(mainmenu)
menuExample.add_command(label="Ouvrir",underline=0, command=Affiche, foreground ='red', background ='yellow',
font =('Comic Sans MS', 11))
## Ajout d'une séparation
menuExample.add_separator()
##Ajout d'une commande
menuExample.add_command(label="Quitter", underline =0, command=root.destroy)
## Menu Fils
menuWindows = Tk.Menu(mainmenu)
mainmenu.add_cascade(label = "Fichier", underline =0, foreground ='red', background ='yellow',
font =('Comic Sans MS', 15),menu=menuExample)
mainmenu.add_cascade(label = "Windows", foreground ='red', background ='yellow', underline =0, menu=menuWindows)
root.configure(menu = mainmenu)
root.wm_state(newstate="zoomed")
root.mainloop() |
Partager