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
| import tkinter as tk
import tkinter.filedialog as tkFD
def open_file():
name = tkFD.askopenfilename(filetypes = [("Fichiers Tex","*.tex")])
if name:
with open(name, "r") as f:
t.insert(tk.INSERT, f.read())
t.update()
root = tk.Tk()
f = tk.Frame(root)
geoargs = {'fill':'both', 'padx':5, 'pady':5}
f.pack(side=tk.BOTTOM, **geoargs)
tk.Button(f, text='Open File', command=open_file).pack(side=tk.LEFT, **geoargs)
tk.Button(f, text='Quit', command=root.quit).pack(side=tk.RIGHT, **geoargs)
xscrollbar = tk.Scrollbar(root, orient=tk.HORIZONTAL)
xscrollbar.pack(side=tk.BOTTOM, fill=tk.X)
yscrollbar = tk.Scrollbar(root)
yscrollbar.pack(side=tk.RIGHT, fill=tk.Y)
t = tk.Text(root, wrap=tk.NONE, xscrollcommand=xscrollbar.set,
yscrollcommand=yscrollbar.set)
t.pack()
xscrollbar.config(command=t.xview)
yscrollbar.config(command=t.yview)
t.focus_set()
root.mainloop() |
Partager