-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtinkter.py
More file actions
executable file
·65 lines (50 loc) · 1.83 KB
/
Copy pathtinkter.py
File metadata and controls
executable file
·65 lines (50 loc) · 1.83 KB
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
import tkinter as tk
import tkinter.ttk as ttk
from tkinter import filedialog
import os
root = tk.Tk()
file = ttk.Frame(root)
file.pack()
fileSelect = ttk.Entry(file, width=49)
fileSelect.pack(side="left")
def loadFiles(filepath):
if filepath:
with open(filepath, "r") as f:
textContent = f.read()
textEditor.delete("1.0", tk.END)
textEditor.insert(tk.END, textContent)
setWindowTitle()
def openFileBrowser():
selectedDir = os.path.join(os.path.dirname(__file__), "txtDocs")
filepath = filedialog.askopenfilename(initialdir = selectedDir)
loadFiles(filepath)
fileBrowse = ttk.Button(file, width=10, text="Browse", command=openFileBrowser)
fileBrowse.pack(side="right")
textEditor = tk.Text(root, height=16, width=60)
textEditor.pack()
def saveText():
file = fileSelect.get()
textContent = textEditor.get("1.0", tk.END)
with open(f"selectedDir/{file}", "w") as f:
f.write(textContent)
saveButton = ttk.Button(root, text="Lagre", width=29, command=saveText)
saveButton.pack(side="right")
exitButton = ttk.Button(root, text="Lukk", width=29, command=root.destroy)
exitButton.pack(side="left")
def setWindowTitle():
filepath = __file__
pathComponents = filepath.split(os.sep)
lastFolders = os.path.join(*pathComponents[-4:-1])
fileName = os.path.basename(filepath)
modTitle = lastFolders + os.sep + fileName
maxLength = 30
if len(modTitle) > maxLength:
sepCount = max(len(pathComponents), 1)
truncatedPath = os.path.join(*pathComponents[:maxLength // sepCount])
truncatedFile = filepath.split(os.sep)[-1]
winTitle = truncatedPath + os.sep + truncatedFile
winTitle = str(winTitle + " - Budget Editor of Text")
root.title(winTitle) # Budget Editor of Text
setWindowTitle()
root.resizable(False, False)
root.mainloop()