81 lines
2.4 KiB
Python
81 lines
2.4 KiB
Python
import tkinter as tk
|
|
import tkinter.ttk as ttk
|
|
import os
|
|
from configparser import ConfigParser
|
|
|
|
## chemicals
|
|
substances = ['Water','Propanol','Aceton']
|
|
clabels = ['x','y','z','volume','z/ml','reakVolume']
|
|
centrys = []
|
|
chem_config = ConfigParser()
|
|
|
|
def load_chem_config():
|
|
chem_config.read(os.path.join(os.path.dirname(__file__), "chemicals.ini"),)
|
|
def conf_chem_write():
|
|
for p in substances:
|
|
chem_config[p] = {}
|
|
for x in centrys:
|
|
if x[0] == p:
|
|
chem_config[p][x[1]] = x[2].get()
|
|
with open(os.path.join(os.path.dirname(__file__), "chemicals.ini"),'w') as f:
|
|
chem_config.write(f)
|
|
def init_chem():
|
|
c =0
|
|
r = 0
|
|
for p in substances:
|
|
frame = ttk.LabelFrame(chemframe,text=p)
|
|
frame.grid(column=c,row=r)
|
|
c +=1
|
|
if c > 3:
|
|
c=0
|
|
r +=1
|
|
for i in range(len(clabels)):
|
|
tk.Label(frame,text=clabels[i]).grid(row=i,column=0)
|
|
var = tk.StringVar()
|
|
entry = tk.Entry(frame,width=10,textvariable=var)
|
|
var.set(chem_config[p][clabels[i]])
|
|
entry.grid(row=i,column=1,sticky='w')
|
|
centrys.append([p,clabels[i],entry])
|
|
|
|
|
|
root = tk.Tk()
|
|
|
|
##init
|
|
load_chem_config()
|
|
substances = chem_config.sections()
|
|
|
|
#configue root
|
|
root.title("Jfs Labrobot")
|
|
root.geometry('800x500+300+300')
|
|
notebook = ttk.Notebook(root)
|
|
notebook.grid(sticky='news',padx=5,pady=5)
|
|
notebook.enable_traversalrightmainframe = ttk.Frame(notebook)
|
|
## mainframe
|
|
mainframe = ttk.Frame(notebook)
|
|
mainframe.columnconfigure(0,weight=1)
|
|
notebook.add(mainframe,text='main',underline=0)
|
|
fra1 = ttk.LabelFrame(mainframe,text=' Test')
|
|
fra1.grid(row=0,column=0,sticky='nw')
|
|
chemsub = tk.StringVar()
|
|
chemlab = tk.StringVar()
|
|
chemit = tk.StringVar()
|
|
|
|
def doit(*args):
|
|
chemit.set(str(chem_config[chemsub.get()][chemlab.get()]))
|
|
|
|
chemopt = ttk.OptionMenu(fra1,chemsub,substances[0],*substances,command=doit)
|
|
chemopt.grid(row=0,column=0,sticky='e')
|
|
chemopt1 = ttk.OptionMenu(fra1,chemlab,clabels[0],*clabels,command=doit)
|
|
chemopt1.grid(row=0,column=1,sticky='e')
|
|
chemerg = ttk.Label(fra1,textvariable=chemit)
|
|
chemerg.grid(row=0,column=2,sticky='ne')
|
|
|
|
##chemicals
|
|
chemframe = ttk.Frame(notebook)
|
|
notebook.add(chemframe,text='chemicals',underline=0)
|
|
init_chem()
|
|
tk.Button(chemframe,text='Load',command = load_chem_config).grid(row=100,column=0,sticky='ew')
|
|
tk.Button(chemframe,text='Save',command = conf_chem_write).grid(row=100,column=1,sticky='ew')
|
|
|
|
|
|
root.mainloop() |