-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsl.pyw
80 lines (61 loc) · 2.38 KB
/
sl.pyw
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
import tkinter as tk
import time
import os
import platform
class Gui(tk.Frame):
def __init__(self, master = None):
tk.Frame.__init__(self, master)
self.row_top = tk.Frame(master)
self.row_bot = tk.Frame(master)
self.row_top.grid(row=0, column=0)
self.row_bot.grid(row=1, column=0, sticky='ew', padx=(10,0))
self.colour_scheme()
master.configure(bg=self.bg)
for frame in [self.row_top, self.row_bot]:
frame.configure(bg=self.bg)
self.add_elements()
self.set_time()
def colour_scheme(self):
self.bg, self.fg, self.ac1, self.ac2, self.ac3 = ('#282828', '#CAD2C5', '#B3B3B3', '#576F72', '#7D9D9C')
def add_elements(self):
self.text_entry = tk.Text(self.row_bot, width=50, height=4, wrap='word', undo=True, insertbackground=self.ac1, selectbackground=self.ac2, inactiveselectbackground=self.ac3)
self.text_entry.bind('<Return>', self.log_entry_event)
self.text_entry.bind('<KP_Enter>', self.log_entry_event)
self.scrolly = tk.Scrollbar(self.row_bot, orient='vertical', command=self.text_entry.yview)
self.text_entry.configure(yscrollcommand=self.scrolly.set)
self.button_enter = tk.Button(self.row_top, text='Enter', command=self.log_entry, activebackground=self.fg, activeforeground=self.bg, cursor='hand2')
self.label_time = tk.Label(self.row_top, text='')
for el in [self.label_time, self.text_entry, self.button_enter]:
el.pack(side='left', pady=2, padx=1)
el.configure(bg=self.bg, fg=self.fg, borderwidth=0)
self.text_entry.focus()
def log_entry_event(self, event):
self.log_entry()
return 'break'
def log_entry(self):
log_record(str(self.text_entry.get('1.0', 'end')))
self.text_entry.delete('1.0', 'end')
def set_time(self):
self.label_time.config(text=get_time())
self.after(333, self.set_time)
def get_geometry():
if platform.system() == 'Windows':
return '425x115+94+0'
else:
return ('%dx130+%d+30' % (program_width := 425, (1920 - program_width) / 2))
def log_record(entry):
try:
with open(os.path.join('Other', 'myLogs.txt'), 'a', encoding='utf-8') as f:
f.write(get_time() + '| ' + str(entry).strip() + '\n')
except IOError as e:
print(e)
def get_time():
return time.strftime('%Y.%m.%d %H:%M:%S')
if __name__ == '__main__':
root = tk.Tk(className='sl')
if platform.system() == 'Linux':
root.tk.call('tk', 'scaling', 1.3)
root.title('Log Recorder')
root.geometry(get_geometry())
app = Gui(master=root)
app.mainloop()