Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- from tkinter import filedialog as fd
- import pathlib
- def openFile():
- filetypes = (
- ('text files', '*.txt'),
- ('All files', '*.*')
- )
- initDir = pathlib.Path().resolve()
- try:
- filename = fd.askopenfilename(
- title='Επιλογή αρχείου',
- initialdir=initDir,
- filetypes=filetypes
- )
- f = open(filename, 'r')
- content_list = f.readlines()
- f.close()
- contnet = ''
- for c in content_list:
- contnet += c
- text_area.delete(1.0,"end")
- text_area.insert(1.0, contnet)
- except Exception as ex:
- print(ex)
- root = tk.Tk()
- root.title('Κείμενα')
- root.geometry('500x300')
- info_label = tk.Label(text='Αναγνωση / Αποθήκευση αρχείου κειμένου')
- info_label.pack()
- text_area = tk.Text()
- text_area.pack()
- openButton = tk.Button(root,text='Άνοιγμα', command=openFile)
- openButton.pack()
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement