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
| # -*-coding:Utf-8 -*-
from __future__ import unicode_literals
import Tkinter
import tkFileDialog
#Fenêtre principale
class Interface(Tkinter.Tk) :
def __init__(self, parent) :
Tkinter.Tk.__init__(self, parent)
self.parent = parent
self.initialize()
# Creation des widgets
def initialize(self) :
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")
self.c = Tkinter.Canvas(self, yscrollcommand=self.ascenseur_y.set, xscrollcommand=self.ascenseur_x.set)
self.c.grid(row=0, column=0, sticky="news")
self.ascenseur_y.config(command=self.c.yview)
self.ascenseur_x.config(command=self.c.xview)
self.grid_rowconfigure(0, weight=1)
self.grid_columnconfigure(0, weight=1)
self.fr = Tkinter.Frame(self.c)
# Bouton ouvir fichier pdf
self.fr.bouton_oeffnen = Tkinter.Button(self.fr, width=12, text=u"PDF wählen", command=self.ButtonSelectPDF, anchor="center", cursor="hand2")
self.fr.bouton_oeffnen.grid(column=0, row=0, padx=10, sticky="W")
self.fr.bouton_oeffnen.bind("<Return>", self.EnterSelectPDF)
# Ce bouton est selectionne par defaut au lancement du programme
self.fr.bouton_oeffnen.focus_set()
# Champ de texte pour entrer le lien vers le dossier contenant les photos
self.fr.pfad = Tkinter.StringVar()
self.fr.entry_pfad = Tkinter.Entry(self.fr, textvariable=self.fr.pfad, width=50)
self.fr.entry_pfad.grid(column=0, row=1, columnspan=2, padx=10, sticky="EW")
# Valeur par defaut dans le champ de texte
self.fr.pfad.set(u"<Pfad bis zum PDF>")
# Configuration Lignes/Colonnes
self.fr.grid_columnconfigure(0, weight=1)
self.fr.grid_columnconfigure(1, weight=1, minsize=40)
self.fr.grid_rowconfigure(0, weight=1, pad=10)
self.fr.grid_rowconfigure(1, weight=1, pad=10)
self.c.create_window(0, 0, window=self.fr)
self.fr.update_idletasks()
self.c.config(scrollregion=self.c.bbox("all"))
# Fonctions associées aux widgets
def ButtonSelectPDF(self) :
""" Ouvre le fichier pdf """
self.fr.pfad.set(tkFileDialog.askopenfilename(title=u"PDF wählen, dann OK anklicken",filetypes=[('PDF-Files','.pdf')]))
def EnterSelectPDF(self, event) :
""" Ouvre le fichier pdf ; cf ci-dessus"""
self.ButtonSelectPDF()
# Hauptfenster wird gebaut
if __name__ == "__main__" :
app = Interface(None)
app.title(u"Kämmerer AG")
app.mainloop() |
Partager