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 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
| # -*-coding:Utf-8 -*-
from __future__ import unicode_literals
import Tkinter
import ImageTk
import Image
class Interface(Tkinter.Tk) :
def __init__(self, parent) :
Tkinter.Tk.__init__(self, parent)
self.parent = parent
self.initialize()
# Creation de nos widgets
def initialize(self) :
# Fenetre principale
# Def Scrollbars
self.ascenseur_y = Tkinter.Scrollbar(self, orient=Tkinter.VERTICAL)
self.ascenseur_x = Tkinter.Scrollbar(self, orient=Tkinter.HORIZONTAL)
self.ascenseur_y.grid(row=0, column=1, sticky="ns")
self.ascenseur_x.grid(row=1, column=0, sticky="ew")
# Def Canvas contenant le Label avec l'image de fond
self.c = Tkinter.Canvas(self, yscrollcommand=self.ascenseur_y.set, xscrollcommand=self.ascenseur_x.set, bg="white", highlightthicknes=0)
self.c.grid(row=0, column=0, sticky="news")
self.c.bind('<Configure>', self.dimensionner)
self.grid_rowconfigure(0, weight=1)
self.grid_columnconfigure(0, weight=1)
self.ascenseur_x.config(command=self.c.xview)
self.ascenseur_y.config(command=self.c.yview)
# Def Frame invisible pour lier la molette souris à la Y-Scrollbar
self.fr = Tkinter.Frame(self.c)
self.fr.pack(expand=True, fill="both")
# Def Label avec l'iamage de fond. Contient les autres widegts
self.apercu_logo="Logo.png"
self.photo = ImageTk.PhotoImage(Image.open(self.apercu_logo))
self.bl = Tkinter.Label(self.c, image=self.photo, bg="white")
self.image_y = self.winfo_height()/2
self.image_x = self.winfo_width()/2
self.c.create_window(450/2, 300/2, window=self.bl, height=500, width=800)
self.bl.update_idletasks()
self.fr.bind_all("<MouseWheel>", self._on_mousewheel_haupt)
# Bouton lancer pdf2pptx - Dans self.bl
self.bouton_pdf2pptx = Tkinter.Button(self.bl, width=13, text=u"Pdf2pptx", command=self.ButtonPdf2pptx, anchor="center", cursor="hand2", padx=0)
self.bouton_pdf2pptx.grid(column=0, row=0, padx=10)
self.bouton_pdf2pptx.bind("<Return>", self.EnterPdf2pptx)
self.bouton_pdf2pptx.focus_set()
# Bouton lancer xls2inp - Dans self.bl
self.bouton_xls2inp = Tkinter.Button(self.bl, width=13, text=u"xls2inp", command=self.ButtonXls2inp, anchor="center", cursor="hand2", padx=0)
self.bouton_xls2inp.grid(column=1, row=0, padx=10)
self.bouton_xls2inp.bind("<Return>", self.EnterXls2inp)
# Bouton lancer Zeichen ersetzer - Dans self.bl
self.bouton_ZeichenErsetzer = Tkinter.Button(self.bl, width=13, text=u"Zeichen ersetzer", command=self.ButtonZeichenErsetzer, anchor="center", cursor="hand2", padx=0)
self.bouton_ZeichenErsetzer.grid(column=2, row=0, padx=10)
self.bouton_ZeichenErsetzer.bind("<Return>", self.EnterZeichenErsetzer)
# Configuration lignes/colonnes - Dans self.bl
self.bl.grid_rowconfigure(0, weight=1, pad=100, minsize=50)
self.bl.grid_columnconfigure(0, weight=1, pad=30, minsize=140)
self.bl.grid_columnconfigure(1, weight=1, pad=30, minsize=140)
self.bl.grid_columnconfigure(2, weight=1, pad=30, minsize=140)
# Logo du cadre de la fenêtre
self.iconbitmap("IcoKAG.ico")
# Options de la fenetre principale
# Redimentionnement autorisée y/n
self.resizable(True, True)
# Création du Canvas principal qui contient tout et config des scrollbars pour qu'elles s'y adaptent
self.image_y = self.winfo_height()/2
self.image_x = self.winfo_width()/2
self.c.create_window(self.image_x, self.image_y, window=self.fr)
self.fr.update_idletasks()
# Taille minimum de la fenêtre
self.minsize(200, 100)
# Taille de la fenêtre à l'ouverture
self.geometry("500x300")
#self.c.config(scrollregion=self.c.bbox("all"))
if self.winfo_width() < 437 :
self.bl.grid_columnconfigure(0, weight=1, pad=30, minsize=self.winfo_width()/3)
self.bl.grid_columnconfigure(1, weight=1, pad=30, minsize=self.winfo_width()/3)
self.bl.grid_columnconfigure(2, weight=1, pad=30, minsize=self.winfo_width()/3)
else :
self.bl.grid_columnconfigure(0, weight=1, pad=30, minsize=140)
self.bl.grid_columnconfigure(1, weight=1, pad=30, minsize=140)
self.bl.grid_columnconfigure(2, weight=1, pad=30, minsize=140)
if self.winfo_height() >= 300 and self.winfo_width() >= 500 :
self.SR = (0, 0, self.photo.width(), self.photo.height())#self.c.bbox("all")
self.SRL = list(self.SR)
self.SRL[2] = self.winfo_width() - 16
self.SRL[3] = self.winfo_height() - 16
self.c.config(scrollregion=tuple(self.SRL))
self.update()
elif self.winfo_height() < 300 and self.winfo_width() >= 500 :
self.SR = (0, 0, self.photo.width(), self.photo.height())#self.c.bbox("all")
self.SRL = list(self.SR)
self.SRL[2] = self.winfo_width() - 16
self.SRL[3] -= 16
self.c.config(scrollregion=tuple(self.SRL))
self.update()
elif self.winfo_height() >= 300 and self.winfo_width() < 500 :
self.SR = (0, 0, self.photo.width(), self.photo.height())#self.c.bbox("all")
self.SRL = list(self.SR)
self.SRL[2] -= 16
self.SRL[3] = self.winfo_height() - 16
self.c.config(scrollregion=tuple(self.SRL))
self.update()
else :
self.SR = (0, 0, self.photo.width(), self.photo.height())#self.c.bbox("all")
self.SRL = list(self.SR)
self.SRL[2] -= 16
self.SRL[3] -= 16
self.c.config(scrollregion=tuple(self.SRL))
self.update()
# On s'assure que Tkinter a termine les rendus graphiques
self.update()
self.bl.update_idletasks()
# Fonctions associées aux widgets de la fenetre principale
def dimensionner(self, event):
""" Gestion du redimentionnement de la taille de la fenêtre :
Repositionne l'image de fond
Modifie la taille des lignes/colonnes """
# Regle la taille des scrollbars et la scrollregion
if self.winfo_width() < 437 :
self.bl.grid_columnconfigure(0, weight=1, pad=30, minsize=self.winfo_width()/3)
self.bl.grid_columnconfigure(1, weight=1, pad=30, minsize=self.winfo_width()/3)
self.bl.grid_columnconfigure(2, weight=1, pad=30, minsize=self.winfo_width()/3)
self.update()
self.c.update_idletasks()
else :
self.bl.grid_columnconfigure(0, weight=1, pad=30, minsize=140)
self.bl.grid_columnconfigure(1, weight=1, pad=30, minsize=140)
self.bl.grid_columnconfigure(2, weight=1, pad=30, minsize=140)
self.update()
self.c.update_idletasks()
if self.winfo_height() >= 300 and self.winfo_width() >= 500 :
self.SR = (0, 0, self.photo.width(), self.photo.height())
self.SRL = list(self.SR)
self.SRL[2] = self.winfo_width() - 16
self.SRL[3] = self.winfo_height() - 16
self.c.config(scrollregion=tuple(self.SRL))
self.update()
self.c.update_idletasks()
elif self.winfo_height() < 300 and self.winfo_width() >= 500 :
self.SR = (0, 0, self.photo.width(), self.photo.height())
self.SRL = list(self.SR)
self.SRL[2] = self.winfo_width() - 16
self.SRL[3] = 300 - 16
self.c.config(scrollregion=tuple(self.SRL))
self.update()
self.c.update_idletasks()
elif self.winfo_height() >= 300 and self.winfo_width() < 500 :
self.SR = (0, 0, self.photo.width(), self.photo.height())
self.SRL = list(self.SR)
self.SRL[2] = 500 - 16
self.SRL[3] = self.winfo_height() - 16
self.c.config(scrollregion=tuple(self.SRL))
self.update()
self.c.update_idletasks()
else :
self.c.config(scrollregion=(0, 0, 484, 284))
self.update()
self.c.update_idletasks()
# Ajuste le Background-label
if self.winfo_height() >= 300 and self.winfo_width() >= 500 :
self.image_y = self.winfo_height()/2
self.image_x = self.winfo_width()/2
self.c.create_window(self.image_x, self.image_y, window=self.bl, height=self.winfo_height(), width=self.winfo_width())
self.update()
self.c.update_idletasks()
elif self.winfo_height() < 300 and self.winfo_width() >= 500 :
self.image_y = 300/2
self.image_x = self.winfo_width()/2
self.c.create_window(self.image_x, self.image_y, window=self.bl, height=300, width=self.winfo_width())
self.update()
self.c.update_idletasks()
elif self.winfo_height() >= 300 and self.winfo_width() < 500 :
self.image_y = self.winfo_height()/2
self.image_x = 500/2
self.c.create_window(self.image_x, self.image_y, window=self.bl, height=self.winfo_height(), width=500)
self.update()
self.c.update_idletasks()
else :
self.image_y = 300/2
self.image_x = 500/2
self.c.create_window(self.image_x, self.image_y, window=self.bl, height=300, width=500)
self.update()
self.c.update_idletasks()
def _on_mousewheel_haupt(self, event):
""" Fonction qui lie la scrollbar principale à la molette de la souris (le /120 est parceque sinon ca scroll trop vite sous windows) """
self.c.yview_scroll(-1*(event.delta/120), "units")
self.update()
self.c.update_idletasks()
def ButtonPdf2pptx(self) :
pass
def EnterPdf2pptx(self, event) :
self.ButtonPdf2pptx()
def ButtonXls2inp(self) :
pass
def EnterXls2inp(self, event) :
self.ButtonXls2inp()
def ButtonZeichenErsetzer(self) :
pass
def EnterZeichenErsetzer(self, event) :
self.ButtonZeichenErsetzer()
# Hauptfenster wird gebaut
if __name__ == "__main__" :
appLauncher = Interface(None)
appLauncher.title(u"Programm-launcher - Kämmerer AG")
appLauncher.mainloop() |
Partager