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
| from tkinter import *
from tkinter import messagebox
from tkinter.filedialog import askopenfilename
from dicos_exercices import *
dic_txt = {
'exA': "EXERCICE A - Pectoraux, épaules, triceps\n\n"
"blablabla",
'exA1': "EXERCICE A1 - Pectoraux, épaules, triceps\n\n"
"blabliblou."
}
dic_img = {
'imgA': 'images/imgA.gif', 'imgA1': 'images/imgA1.gif', 'imgA2': 'images/imgA2.gif',
'imgA3': 'images/imgA3.gif', 'imgA456': 'images/imgA456.gif',
'imgA7': 'images/imgA7.gif'
}
# Fenêtre principale
class MyWindow(Tk):
def __init__(self):
Tk.__init__(self)
self.createMenuBar()
self.title( "Programme Lafay V1.0" )
def createMenuBar(self):
menuBar = Menu(self)
menuFile = Menu(menuBar, tearoff = 0)
menuFile.add_command(label = "Nouveau", command = None)
menuFile.add_command(label = "Ouvrir", command = self.openFile)
menuFile.add_command(label = "Sauvegarder", command = None)
menuFile.add_separator()
menuFile.add_command(label = "Exit", command = self.quit)
menuBar.add_cascade( label = "Fichier", menu = menuFile)
menuEdit = Menu(menuBar, tearoff = 0)
menuEdit.add_command(label = "Annuler", command = None)
menuEdit.add_separator()
menuEdit.add_command(label = "Copier", command = None)
menuEdit.add_command(label = "Couper", command = None)
menuEdit.add_command(label = "Coller", command = None)
menuBar.add_cascade( label = "Edition", menu = menuEdit)
# Menu exercices
menu_exercices = Menu(menuBar, tearoff = 0)
menuBar.add_cascade(label = "Exercices", menu = menu_exercices)
menu_exercices_a = Menu(menu_exercices, tearoff = 0)
menu_exercices.add_cascade(label='A', menu = menu_exercices_a)
menu_exercices_a.add_command(label = "A", command = lambda : MyWindow.aff_exercice(self, dic_txt['exA'], dic_img['imgA']))
menu_exercices_a.add_command(label = "A1", command = lambda : MyWindow.aff_exercice(self, dic_txt['exA1'], dic_img['imgA1']))
menu_exercices_a.add_command(label = "A2", command = lambda : MyWindow.aff_exercice(self, dic_txt['exA2'], dic_img['imgA2']))
menu_exercices_a.add_command(label = "A3", command = lambda : MyWindow.aff_exercice(self, dic_txt['exA3'], dic_img['imgA3']))
#etc.
menu_exercices_b = Menu(menu_exercices, tearoff = 0)
menu_exercices.add_cascade(label='B', menu = menu_exercices_b)
menu_exercices_b.add_command(label = "B", command = lambda : MyWindow.aff_exercice(self, dic_txt['exB'], dic_img['imgB']))
menu_exercices_b.add_command(label = "B1", command = lambda : MyWindow.aff_exercice(self, dic_txt['exB1'], dic_img['imgB1']))
menu_exercices_b.add_command(label = "B2", command = lambda : MyWindow.aff_exercice(self, dic_txt['exB2'], dic_img['imgB2']))
menu_exercices_c = Menu(menu_exercices, tearoff = 0)
menu_exercices.add_cascade(label='C', menu = menu_exercices_c)
menu_exercices_c.add_command(label = "C", command = lambda : MyWindow.aff_exercice(self, dic_txt['exC'], dic_img['imgC']))
menu_exercices_c.add_command(label = "C1", command = lambda : MyWindow.aff_exercice(self, dic_txt['exC1'], dic_img['imgC1']))
# etc.
menuHelp = Menu(menuBar, tearoff = 0)
menuHelp.add_command(label = "A propos", command = self.a_propos)
menuBar.add_cascade( label = "Aide", menu = menuHelp)
self.config(menu = menuBar)
def openFile(self):
file = askopenfilename(title="Choisissez un fichier à ouvrir",
filetypes=[("PNG image", ".png"), ("GIF image", ".gif"), ("All files", ".*")])
print( file )
#Fonction permettant d'afficher des images dans une fenêtre gauche et des textes dans une fenêtre droite
def aff_exercice(self, txt, img):
text1 = Text(window, height = 30, width = 50)
photo = PhotoImage(file = img)
text1.insert(END, '\n')
text1.image_create(END, image = photo)
text1.grid(row = 3, column = 1)
text2 = Text(window, height = 30, width = 50)
scroll = Scrollbar(window, command = text2.yview)
text2.configure(yscrollcommand = scroll.set)
text2.configure(wrap = 'word')
text2.tag_configure('bold_italics', font = ('Arial', 12, 'bold', 'italic'))
text2.tag_configure('big', font=('Verdana', 20, 'bold'))
text2.tag_configure('color',
foreground = '#476042',
font = ('Tempus Sans ITC', 12, 'bold'))
quote = txt
text2.insert(END, quote, 'color')
text2.grid(row = 3, column = 2, padx = 10, pady = 5)
scroll.grid(side=RIGHT, fill=Y)
def a_propos():
tkinter.messagebox.showinfo("A propos","Programme Lafay \ P.Y.D \ 2019")
window = MyWindow()
window.mainloop() |
Partager