from tkinter.colorchooser import askcolor from tkinter import filedialog from tkinter import messagebox import tkinter as tk import csv import numpy as np ####################################### object class Jfsphoto (object): def __init__(self): self.nm = 0 self.nmi = 0 self.nm2 = 0 self.nm2i = 0 def test1(self): win = tk.Toplevel() win.geometry("400x200+30+30") self.lab1 = tk.Label(win, text='please enter filenames and nm of the peaks').grid(row=0,column=0,columnspan=6) ########## first peak self.tnm = tk.StringVar() self.tnm.set(str(self.nm)) self.tnmi = tk.StringVar() self.tnmi.set(str(self.nmi)) self.lab2 = tk.Label(win,text='first Peak nm').grid(row=1,column=0) self.en1 = tk.Entry(win,textvariable=self.tnm, width= 10).grid(row=1,column=1) self.bt1 = tk.Button(win,text="select File",command=lambda: self.openfile(1)).grid(row=1,column=2) self.lnm = tk.Label(win,textvariable =self.tnm).grid(row=1,column=3) self.lnm = tk.Label(win,text =" nm by index ").grid(row=1,column=4) self.lmi = tk.Label(win,textvariable=self.tnmi).grid(row=1,column=5) ########## second peak self.tnm2 = tk.StringVar() self.tnm2.set(str(self.nm2)) self.tnm2i = tk.StringVar() self.tnm2i.set(str(self.nm2i)) self.lab3 = tk.Label(win,text='second Peak nm').grid(row=2,column=0) self.en2 = tk.Entry(win,textvariable=self.tnm2, width= 10).grid(row=2,column=1) self.bt2 = tk.Button(win,text="select File",command=lambda: self.openfile(2)).grid(row=2,column=2) self.lnm2 = tk.Label(win,textvariable =self.tnm2).grid(row=2,column=3) self.lnm2 = tk.Label(win,text =" nm by index ").grid(row=2,column=4) self.lm2i = tk.Label(win,textvariable=self.tnm2i).grid(row=2,column=5) #a=tk.Label(win,text='Hi there') #a.place(x=10,y=10,width=40,height=25) #b=tk.Button(win,text='Ok then',command=win.destroy) #b.place(x=60,y=10,width=60,height=25) ## modal win.focus_set() win.grab_set() win.wait_window() def checkit(self): print(self.tnm.get()) def info(self): print(f'nm {self.nm} nmi {self.nmi}') def openfile(self,xx): rxData16 = np.zeros(3694, np.uint16) filename = filedialog.askopenfilename(defaultextension=".dat", title="Open file") line_count = 0 try: with open(filename) as csvfile: readCSV = csv.reader(csvfile, delimiter=' ') for row in readCSV: if (line_count == 3): self.SHsent = int(row[1]) self.ICGsent = int(row[6]) if (line_count > 3): rxData16[line_count-4] = int(row[1]) line_count += 1 if (xx==1): self.nmi = np.argmin(rxData16) self.tnmi.set(str(self.nmi)) if (xx==2): self.nm2i = np.argmin(rxData16) self.tnm2i.set(str(self.nm2i)) self.checkit() except IOError: messagebox.showerror("By the great otter!","There's a problem opening the file.")