-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit_json.py
73 lines (59 loc) · 2.72 KB
/
edit_json.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
import json
import tkinter as tk
from tkinter import messagebox
import subprocess
import os
class JsonEditor:
def __init__(self, master):
self.master = master
master.title("JSON Editor")
# Load JSON data
with open('config.json', 'r', encoding='utf-8') as f:
self.data = json.load(f)
# Create labels and entries
self.label_date_str = tk.Label(master, text="出款日")
self.label_date_str.pack()
self.entry_date_str = tk.Entry(master)
self.entry_date_str.insert(0, self.data['date_str'])
self.entry_date_str.pack()
self.label_days_to_add = tk.Label(master, text="账期")
self.label_days_to_add.pack()
self.entry_days_to_add = tk.Entry(master)
self.entry_days_to_add.insert(0, self.data['days_to_add'])
self.entry_days_to_add.pack()
self.label_contract1 = tk.Label(master, text="订单编号")
self.label_contract1.pack()
self.entry_contract1 = tk.Entry(master)
self.entry_contract1.insert(0, self.data['contract1'])
self.entry_contract1.pack()
self.label_contract_amount = tk.Label(master, text="订单金额")
self.label_contract_amount.pack()
self.entry_contract_amount = tk.Entry(master)
self.entry_contract_amount.insert(0, self.data['contract_amount'])
self.entry_contract_amount.pack()
self.label_factoring_amount = tk.Label(master, text="融资金额")
self.label_factoring_amount.pack()
self.entry_factoring_amount = tk.Entry(master)
self.entry_factoring_amount.insert(0, self.data['factoring_amount'])
self.entry_factoring_amount.pack()
self.save_button = tk.Button(master, text="Save", command=self.save)
self.save_button.pack()
self.run_button = tk.Button(master, text="生成合同", command=self.run_exe)
self.run_button.pack()
def save(self):
# Update JSON data
self.data['date_str'] = self.entry_date_str.get()
self.data['days_to_add'] = int(self.entry_days_to_add.get())
self.data['contract1'] = self.entry_contract1.get()
self.data['contract_amount'] = self.entry_contract_amount.get()
self.data['factoring_amount'] = self.entry_factoring_amount.get()
# Save JSON data
with open('config.json', 'w', encoding='utf-8') as f:
json.dump(self.data, f, indent=4)
messagebox.showinfo("Information","Data saved successfully")
def run_exe(self):
subprocess.call(os.path.join(os.getcwd(), "auto_contract.exe"))
self.master.destroy()
root = tk.Tk()
json_editor = JsonEditor(root)
root.mainloop()