-
Notifications
You must be signed in to change notification settings - Fork 6
/
config_gui.py
83 lines (64 loc) · 2.65 KB
/
config_gui.py
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
81
82
83
import json
import os
import sys
import tkinter as tk
def cancelclick():
sys.exit(0)
class GUI:
def okclick(self):
data = {"url": self.urlentry.get(),
"telegramAPIKEY": self.apikeyentry.get(),
"telegramCHATID": self.chatidentry.get(),
"databaseFile": self.databaseentry.get(),
"sleep": self.sleepeentry.get()
}
with open(self.file_name, 'w') as config_file:
json.dump(data, config_file)
config_file.close()
self.window.destroy()
pass
def __init__(self, file_name):
self.file_name = file_name
self.window = tk.Tk()
self.window.geometry('605x300')
urllabel = tk.Label(text="url")
self.urlentry = tk.Entry(width=100, justify=tk.CENTER)
databaselabel = tk.Label(text="databaseFile")
self.databaseentry = tk.Entry(width=100, justify="center")
apikeylabel = tk.Label(text="telegramAPIKEY")
self.apikeyentry = tk.Entry(width=100, justify="center")
chatidlabel = tk.Label(text="telegramCHATID")
self.chatidentry = tk.Entry(width=100, justify="center")
sleeplabel = tk.Label(text="sleep")
self.sleepeentry = tk.Entry(width=100, justify="center")
okbutton = tk.Button(self.window, text="OK", command=self.okclick)
cancelbutton = tk.Button(self.window, text="Cancel", command=cancelclick)
urllabel.grid(column=0, row=0)
self.urlentry.grid(column=0, row=1)
databaselabel.grid(column=0, row=2)
self.databaseentry.grid(column=0, row=3)
apikeylabel.grid(column=0, row=4)
self.apikeyentry.grid(column=0, row=5)
chatidlabel.grid(column=0, row=6)
self.chatidentry.grid(column=0, row=7)
sleeplabel.grid(column=0, row=8)
self.sleepeentry.grid(column=0, row=9)
okbutton.grid(column=0, row=10)
cancelbutton.grid(column=0, row=11)
if os.path.isfile(file_name):
with open(file_name) as config_file:
config = json.load(config_file)
self.urlentry.insert(0, config["url"])
self.apikeyentry.insert(0, config["telegramAPIKEY"])
self.chatidentry.insert(0, config["telegramCHATID"])
self.databaseentry.insert(0, config["databaseFile"])
self.sleepeentry.insert(0, config["sleep"])
config_file.close()
else:
self.databaseentry.insert(0, "database.db")
self.sleepeentry.insert(0, "10")
self.window.mainloop()
try:
self.window.update()
except Exception:
pass