def __init__(self, master, parentWindow): frame = Frame(master) frame.pack() self.frame = frame # for destroy purpose self.master = master self.parentWindow = parentWindow # database with images self.imgDB = tm.cdb.imgDB # for database.get(item) self.item = 1 self.labelImgPlace = Label(frame, text="Image from database \n (click next)") self.labelImgPlace.grid(row=0, column=1) # buttons for going trought imgDB self.buttonNext = Button(frame, text="Next", command=self.next) self.buttonNext.grid(row=2, column=0) self.buttonBack = Button(frame, text="Back", command=self.back) self.buttonBack.grid(row=3, column=0) # label for name of class self.varForLabel = StringVar() self.labelClassName = Label(frame, textvariable=self.varForLabel) self.labelClassName.grid(row=4, column=0) self.button = Button(frame, text="load image", command=self.load_image) # self.button.grid(row=0, column=0) self.label = 0 # self.label=Label(frame,image=imgP) # self.label.pack(side=RIGHT) self.things = self.parentWindow.childResultList # ["cup","banana","pencil"] for i in range(len(self.things)): b = Radiobutton(self.frame, text=self.things[i], value=i) # write i-ths element from list to database as label b.config(command=lambda iter=i: self.choice_class(iter)) b.deselect() b.grid(row=i+1, column=2)
def _build_output_format(self, form): ''' Seletor de formato de saída ''' self.output_format_label = Label(form, text='Formatos de saída:', anchor=W) self.output_format_label.grid(row=2, column=0, sticky=W) formats_frame = Frame(form, relief=GROOVE, borderwidth=1) formats_frame.grid(row=2, column=1, sticky=W + E) self.output_format = StringVar() self.output_format.set('') for label in ('XLSX', 'XLS', 'CSV'): radio = Radiobutton(formats_frame, text=label, value=label, variable=self.output_format, tristatevalue=0) radio.pack(anchor=W) radio.deselect()
class Ventana(Frame): def __init__(self, parent): Frame.__init__(self, parent) self.parent = parent self.canvas = None self.input_tam = None self.barra = None self.barra_normal = None self.barra_soldado = None self.barra_reina = None self.label_probabilidades = None self.tiempo_vida = 100 self.cuadros = None self.matriz = None self.tam = 100 self.tam_cuadro = 10 self.hormigas = list() self.pausa = True self.distribucion = .05 self.mi_var = IntVar() self.mi_var.set(1) self.radio1 = None self.radio2 = None self.radio3 = None self.tiempo = 0 self.contador = [0, 0, 0] self.nom_archivo = "{}.csv".format(self.obtener_hora()) self.archivo = None self.probabilidades = [.9, .08, .02] def init_ui(self): self.parent.title("Hormiga de Lagnton") self.pack(fill=tk.BOTH, expand=1) self.canvas = Canvas(self, relief='raised', width=1000, height=1000) scroll = Scrollbar(self, orient=tk.VERTICAL) scroll.pack(side=tk.RIGHT, fill=tk.Y) scroll.config(command=self.canvas.yview) self.canvas.config(yscrollcommand=scroll.set) self.canvas.pack(side=tk.LEFT) Label(self, text="Tamaño:", font=(20, )).pack(side=tk.TOP) self.input_tam = Entry(self, fg="black", bg="white") self.input_tam.insert(10, "100") self.input_tam.pack(side=tk.TOP) Label(self, text="Porcentaje de hormigas", font=(20, )).pack(side=tk.TOP) self.barra = Scale(self, from_=0, to=100, orient=tk.HORIZONTAL, tickinterval=50) self.barra.set(5) self.barra.pack(side=tk.TOP) Label(self, text="Tipo de hormiga:", font=(20, )).pack(side=tk.TOP) self.radio1 = Radiobutton(self, text="Obrera", variable=self.mi_var, value=1, command=self.seleccion, indicatoron=False, selectcolor="white", font=(20, ), fg="black") self.radio2 = Radiobutton(self, text="Soldado", variable=self.mi_var, value=2, command=self.seleccion, indicatoron=False, selectcolor="orange", font=(20, ), fg="black") self.radio3 = Radiobutton(self, text="Reina", variable=self.mi_var, value=3, command=self.seleccion, indicatoron=False, selectcolor="purple", font=(20, ), fg="black") self.radio1.pack(side=tk.TOP) self.radio2.pack(side=tk.TOP) self.radio3.pack(side=tk.TOP) self.radio1.select() self.radio2.deselect() self.radio3.deselect() self.label_probabilidades = Label(self, text="Suma de probailidades: 100%", font=(20, )) self.label_probabilidades.pack(side=tk.TOP) Label(self, text="Probabilidad de hormigas normales:", font=(20, )).pack(side=tk.TOP) valor1 = StringVar(self) valor1.set("90") self.barra_normal = Spinbox(self, from_=0, to=100, command=self.mover_spinner, textvariable=valor1) self.barra_normal.pack(side=tk.TOP) Label(self, text="Probabilidad de hormigas soldado:", font=(20, )).pack(side=tk.TOP) valor2 = StringVar(self) valor2.set("8") self.barra_soldado = Spinbox(self, from_=0, to=100, command=self.mover_spinner, textvariable=valor2) self.barra_soldado.pack(side=tk.TOP) Label(self, text="Probabilidad de hormigas reina:", font=(20, )).pack(side=tk.TOP) valor3 = StringVar(self) valor3.set("2") self.barra_reina = Spinbox(self, from_=0, to=100, command=self.mover_spinner, textvariable=valor3) self.barra_reina.pack(side=tk.TOP) btn_iniciar = Button(self, text="Iniciar/Reiniciar", command=self.iniciar, font=(20, )) btn_iniciar.pack(side=tk.TOP) btn_pausa = Button(self, text="Reanudar/Pausa", command=self.empezar_detener, font=(20, )) btn_pausa.pack(side=tk.TOP) Label(self, text="Relación de colores y \n posicion de las hormiga:", font=(20, )).pack(side=tk.TOP) Label(self, text="Abajo", bg="blue", font=(20, )).pack(side=tk.TOP) Label(self, text="Arriba", bg="red", font=(20, )).pack(side=tk.TOP) Label(self, text="Izquierda", bg="green", font=(20, )).pack(side=tk.TOP) Label(self, text="Derecha", bg="yellow", fg="black", font=(20, )).pack(side=tk.TOP) def mover_spinner(self): print("moviendo normal") aux1 = int(self.barra_normal.get()) aux2 = int(self.barra_soldado.get()) aux3 = int(self.barra_reina.get()) self.probabilidades[0] = aux1 / 100 self.probabilidades[1] = aux2 / 100 self.probabilidades[2] = aux3 / 100 valor = aux1 + aux2 + aux3 texto = "Suma de probabilidades {} %".format(valor) self.label_probabilidades.configure(text=texto) def iniciar(self): print("iniciar") self.nom_archivo = "{}.csv".format(self.obtener_hora()) self.archivo = open(self.nom_archivo, "w") self.archivo.close() self.contador[:] = [0, 0, 0] self.tiempo = 0 self.hormigas[:] = [] self.canvas.delete('all') self.update_idletasks() self.tam = int(self.input_tam.get()) self.tam_cuadro = 0 while self.tam_cuadro * self.tam < 1000: self.tam_cuadro += 1 if self.tam_cuadro * self.tam > 1000: self.tam_cuadro -= 1 self.distribucion = self.barra.get() / 100 self.probabilidades[0] = int(self.barra_normal.get()) / 100 self.probabilidades[1] = int(self.barra_soldado.get()) / 100 self.probabilidades[2] = int(self.barra_reina.get()) / 100 self.pausa = True self.cuadros = np.zeros(shape=(self.tam, self.tam), dtype=int) self.matriz = np.random.choice( [1, 0], size=(self.tam, self.tam), p=[self.distribucion, 1 - self.distribucion]) self.redibujar() def seleccion(self): print(str(self.mi_var.get())) def crear_hormiga(self, j, i): tipo = np.random.choice([1, 2, 3], p=self.probabilidades) if tipo == 1: hormiga = Hormiga(j, i, self.tam) self.contador[0] += 1 elif tipo == 2: hormiga = Soldado(j, i, self.tam) self.contador[1] += 1 else: hormiga = Reina(j, i, self.tam) self.contador[2] += 1 hormiga.orientacion = np.random.choice(['N', 'S', 'E', 'O']) return hormiga @staticmethod def obtener_hora(): return datetime.datetime.fromtimestamp( time.time()).strftime('%Y-%m-%d_%H:%M:%S') def redibujar(self): print("redibujar") for i in range(self.tam): for j in range(self.tam): if self.matriz[i, j] == 1: self.matriz[i, j] = 0 hormiga = self.crear_hormiga(j, i) self.cuadros[i, j] = self.canvas.create_rectangle( 0 + (j * self.tam_cuadro), 0 + (i * self.tam_cuadro), self.tam_cuadro + (j * self.tam_cuadro), self.tam_cuadro + (i * self.tam_cuadro), fill=hormiga.color, width=0, tag="btncuadrito") self.hormigas.append(hormiga) else: self.cuadros[i, j] = self.canvas.create_rectangle( 0 + (j * self.tam_cuadro), 0 + (i * self.tam_cuadro), self.tam_cuadro + (j * self.tam_cuadro), self.tam_cuadro + (i * self.tam_cuadro), fill="black", width=0, tag="btncuadrito") self.canvas.tag_bind("btncuadrito", "<Button-1>", self.pulsar_cuadrito) self.canvas.tag_bind("btncuadrito", "<Button-3>", self.borrar_cuadrito) self.update_idletasks() print(self.contador) def borrar_cuadrito(self, event): print("borrar_cuadrito") item = self.canvas.find_closest(event.x, event.y)[0] y, x = np.where(self.cuadros == item) contador = 0 for hormiga in self.hormigas: if hormiga.x == x and hormiga.y == y: self.contador[hormiga.tipo - 1] -= 1 if self.matriz[hormiga.y, hormiga.x] == 1: self.canvas.itemconfig(item, fill="white") else: self.canvas.itemconfig(item, fill="black") break contador += 1 if contador < len(self.hormigas): self.hormigas.pop(contador) def pulsar_cuadrito(self, event): print("pulsar_cuadrito") item = self.canvas.find_closest(event.x, event.y)[0] y, x = np.where(self.cuadros == item) crear = True for hormiga in self.hormigas: if hormiga.x == x and hormiga.y == y: hormiga.cambiar() crear = False self.canvas.itemconfig(item, fill=colores_dict[hormiga.orientacion]) break if crear: if self.mi_var.get() == 1: hormiga = Hormiga(x[0], y[0], self.tam) self.contador[0] += 1 elif self.mi_var.get() == 2: hormiga = Soldado(x[0], y[0], self.tam) self.contador[1] += 1 else: hormiga = Reina(x[0], y[0], self.tam) self.contador[2] += 1 self.hormigas.append(hormiga) self.canvas.itemconfig(item, fill=colores_dict[hormiga.orientacion]) def animacion(self): if not self.pausa: archivo = open(self.nom_archivo, "a") archivo.write("{},{},{},{}\n".format(self.tiempo, self.contador[0], self.contador[1], self.contador[2])) archivo.close() reinas = list() soldados = list() cont = 0 print("primer for") for hormiga in self.hormigas: if hormiga.tipo == tipos_dict["reina"]: reinas.append(cont) elif hormiga.tipo == tipos_dict["soldado"]: soldados.append(cont) cont += 1 print("Segundo for") for i in reinas: for j in soldados: if self.hormigas[i].x == self.hormigas[ j].x and self.hormigas[i].y == self.hormigas[j].y: self.hormigas.append( self.crear_hormiga(self.hormigas[i].x, self.hormigas[i].y)) conjunto = set() print("Tercer for") for hormiga in self.hormigas: if hormiga.vida == self.tiempo_vida: self.contador[hormiga.tipo - 1] -= 1 self.hormigas.remove(hormiga) continue if self.matriz[hormiga.y, hormiga.x] == 0: if (hormiga.y, hormiga.x) not in conjunto: self.matriz[hormiga.y, hormiga.x] = 1 conjunto.add((hormiga.y, hormiga.x)) self.canvas.itemconfig(self.cuadros[hormiga.y, hormiga.x], fill=hormiga.color) hormiga.mover(0) else: if (hormiga.y, hormiga.x) not in conjunto: self.matriz[hormiga.y, hormiga.x] = 0 conjunto.add((hormiga.y, hormiga.x)) self.canvas.itemconfig(self.cuadros[hormiga.y, hormiga.x], fill="black") hormiga.mover(1) self.canvas.itemconfig(self.cuadros[hormiga.y, hormiga.x], fill=colores_dict[hormiga.orientacion]) self.update_idletasks() self.after(100, self.animacion) self.tiempo += 1 def empezar_detener(self): print("empezar_detener") self.pausa = not self.pausa self.animacion()
def rest_review(): def main_action(): flag=True res_id=ip.get().lower() if(param.get()==1): if(res_id not in rest_id_dict.keys()): flag=False else: name=rest_id_dict[res_id] else: if(res_id not in rest_id_dict.values()): flag=False else: name=res_id if(flag): label6.config(state=NORMAL) label7.config(state=NORMAL) label8.config(state=NORMAL) label6.delete('1.0', END) label7.delete('1.0', END) label8.delete('1.0', END) positive_reviews, negative_reviews, insufficient_data_to_classify,indexWiseScore = classifyReviewsOf(rest_index_dict[name]) positive=len(positive_reviews) negative=len(negative_reviews) neutral=len(insufficient_data_to_classify) total=positive+negative+neutral positive_percentage=(positive*100)//total negative_percentage=(negative*100)//total neutral_percentage=(neutral*100)//total label6.insert(INSERT,str(positive_percentage)+"%") label7.insert(INSERT,str(neutral_percentage)+"%") label8.insert(INSERT,str(negative_percentage)+"%") label6.config(state=DISABLED) label7.config(state=DISABLED) label8.config(state=DISABLED) else: messagebox.showinfo("Error", "Invalid Restaurant. No such restaurant found.") def radio(): if(param.get()==1): label2.config(text="Enter ID:") else: label2.config(text="Enter Name:") newwin = Toplevel(root) newwin.resizable(False, False) newwin.title("Restaurant Review") newwin.geometry("310x389") newwin.grid_columnconfigure(0, weight=1, uniform="fred") newwin.grid_columnconfigure(1, weight=1, uniform="fred") C = Canvas(newwin, bg="blue", height=389, width=310) filename = PhotoImage(file = "bg.png") background_label = Label(newwin, image=filename) background_label.place(x=0, y=0, relwidth=1, relheight=1) param=IntVar() label1=Label(newwin,text="Search by:",bg='#ffae93') label1.grid(column=0,row=0,pady=(120,0)) rb1=Radiobutton(newwin,text="Restauant ID",bg='#ffae93',padx = 10,variable=param,value=1,command=radio) rb1.grid(column=1,row=0,pady=(120,0),sticky=W) rb2=Radiobutton(newwin,text="Restauant Name",bg='#ffae93',padx = 10,variable=param,value=2,command=radio) rb2.grid(column=1,row=1,sticky=W) rb1.select() rb2.deselect() label2=Label(newwin,text="Enter ID:",bg='#ffae93') label2.grid(column=0,row=2,pady=(10,10)) ip=Entry(newwin,width=20) ip.grid(column=1,row=2,pady=(10,10),sticky=W) button1 =Button(newwin, text ="View Ratings", command =main_action) button1.grid(columnspan=2,row=3,pady=(5,0)) up=PhotoImage(file="thumbsup.png") down=PhotoImage(file="thumbsdown.png") nuetral=PhotoImage(file="nuetralthumb.png") label3=Label(newwin,image=up) label3.grid(column=0,row=4,pady=2,sticky=E,padx=30) label4=Label(newwin,image=nuetral) label4.grid(column=0,row=5,pady=2,sticky=E,padx=30) label5=Label(newwin,image=down) label5.grid(column=0,row=6,pady=2,padx=30,sticky=E) label6=Text(newwin,font=("Helvetica", 24),fg="green",width=5,height=1) label6.grid(column=1,row=4,pady=2,sticky=W) label7=Text(newwin,font=("Helvetica", 24),fg="yellow",width=5,height=1) label7.grid(column=1,row=5,pady=2,sticky=W) label8=Text(newwin,font=("Helvetica", 24),fg="red",width=5,height=1) label8.grid(column=1,row=6,pady=2,sticky=W) label6.config(state=DISABLED) label7.config(state=DISABLED) label8.config(state=DISABLED) C.grid() newwin.mainloop()
def __queryDB(self): y = datetime.now().year m = datetime.now().month d = datetime.now().day today = "{:0>2d}".format(d) + '/' + "{:0>2d}".format(m) + '/' + str(y) self.query_dict = { 'cgi': None, 'tec': '234', 'date': { 'first': '01/01/2013', 'last': today, 'd_all': False }, 'pol': { 'cp': None, 'loc': None, 'con': None, 'dis': None }, 'fis': { 'form': None, 'lat': None, 'lon': None, 'lat2': None, 'lon2': None, 'radius': None }, 'kmz': { 'ico_or_pol': None, 'n': 338, 'scale': 1, 'color': "orange", 'radius': None, 'alt': 35, 'amp': 110 } } # MAIN WINDOW ######################################################### # --- Theme configuration --------------------------------------------- bg = "gray25" fg = "dark orange" font = ("Helvetica", "10", "bold") self.style.theme_use("vladimir") tfs = ttk.Style() tfs.configure("TFrame", background="#404040") # --- Toplevel -------------------------------------------------------- tl = Toplevel(self.master) #tl.geometry("410x420") tl.geometry("530x420") tl.configure(borderwidth=5, bg=bg) tl.title("Pesquisar Base de Dados") icons = os.getcwd() + os.sep + "icons" + os.sep # path to icons icon = icons + "maps.ico" tl.iconbitmap(icon) tl.resizable(width=FALSE, height=FALSE) # --- Base Frame ------------------------------------------------------ f1 = Frame(tl, bg=bg) f1.pack_propagate(0) # don't shrink f1.pack(side=BOTTOM, padx=0, pady=0, expand=TRUE, fill=BOTH) # --- Notebook -------------------------------------------------------- nf = fontTK.Font(root=tl, family='helvetica', size='12', weight='bold') s = ttk.Style() s.configure('.', font=nf) n = ttk.Notebook(f1) n.pack(side=TOP) # --- Messages / Log Frame -------------------------------------------- self.msg = StringVar() self.msg.set("Log...\nMensagens do programa...") l1 = Message(f1, bg=fg, bd=5, fg=bg, textvariable=self.msg, font=("Helvetica", "10", "bold italic"), width=500) l1.pack_propagate(0) l1.pack(expand=TRUE, fill=BOTH, pady=5) # --- Pesquisar Button ------------------------------------------------ b = Button(f1, text="Pesquisar", command=self.__queryDB_button, width=10, bg="forest green", fg="white smoke", font=("Helvetica", "8", "bold")) b.pack(side=BOTTOM, anchor=E) # CGI TAB ############################################################# # --- Main Frame ------------------------------------------------------ tab_cgi = ttk.Frame(n) n.add(tab_cgi, text='CGI') # --- inside Frame ---------------------------------------------------- f_cgi = ttk.Frame(tab_cgi) f_cgi.pack_propagate(0) f_cgi.pack(padx=16, pady=33) # --- Labels ---------------------------------------------------------- cgi_l1 = Label(f_cgi, text=None, bg=bg) cgi_l2 = Label(f_cgi, text="Operadora", bg=bg, fg=fg, width=7, justify=RIGHT) cgi_l3 = Label(f_cgi, text="LAC", bg=bg, fg=fg, width=7, justify=RIGHT) cgi_l4 = Label(f_cgi, text="CID", bg=bg, fg=fg, width=7, justify=RIGHT) cgi_l5 = Label(f_cgi, text="CGI", bg=bg, fg=fg) cgi_l1.grid(row=0, pady=0) cgi_l2.grid(row=1, column=0, padx=5, pady=5) cgi_l3.grid(row=1, column=2, pady=5) cgi_l4.grid(row=1, column=4, pady=5) cgi_l5.grid(row=4, pady=5, padx=5) # --- Entries --------------------------------------------------------- self.cgi_e1 = Entry(f_cgi, width=2) self.cgi_e2 = Entry(f_cgi, width=4) self.cgi_e3 = Entry(f_cgi, width=6) self.cgi_e4 = Entry(f_cgi, width=25) self.cgi_e1.grid(row=1, column=1, pady=5) self.cgi_e2.grid(row=1, column=3, pady=5) self.cgi_e3.grid(row=1, column=5, pady=5) self.cgi_e4.grid(row=4, column=1, columnspan=4, pady=5) # --- Separator ------------------------------------------------------- cgi_s = ttk.Separator(f_cgi, orient=HORIZONTAL) cgi_s.grid(row=3, column=0, columnspan=6, sticky=EW, padx=5, pady=5) # TECNOLOGIA TAB ###################################################### # --- Main Frame ------------------------------------------------------ tab_tec = ttk.Frame(n) n.add(tab_tec, text='Tecnologia') # --- inside Frame ---------------------------------------------------- f_tec = ttk.Frame(tab_tec) f_tec.pack_propagate(0) f_tec.pack(padx=40, pady=45) # --- variables ------------------------------------------------------- self.tec_2g = IntVar() self.tec_3g = IntVar() self.tec_4g = IntVar() # --- Checkbuttons ---------------------------------------------------- tec_cb1 = Checkbutton(f_tec, text="2G", onvalue=2, variable=self.tec_2g, bg=bg, fg=fg) tec_cb2 = Checkbutton(f_tec, text="3G", onvalue=3, variable=self.tec_3g, bg=bg, fg=fg) tec_cb3 = Checkbutton(f_tec, text="4G", onvalue=4, variable=self.tec_4g, bg=bg, fg=fg) tec_cb1.grid(row=1, pady=5, padx=5) tec_cb2.grid(row=2, pady=5, padx=5) tec_cb3.grid(row=3, pady=5, padx=5) # --- Labels ---------------------------------------------------------- tec_l1 = Label(f_tec, text="(GSM)", bg=bg, fg=fg) tec_l2 = Label(f_tec, text="(WCDMA, HSPA, UMTS)", bg=bg, fg=fg) tec_l3 = Label(f_tec, text="(WIMAX, LTE)", bg=bg, fg=fg) tec_l1.grid(row=1, column=1, pady=5, sticky=W) tec_l2.grid(row=2, column=1, pady=5) tec_l3.grid(row=3, column=1, pady=5, sticky=W) # DATA TAB ############################################################ # --- Main Frame ------------------------------------------------------ tab_dat = ttk.Frame(n) n.add(tab_dat, text='Data') # --- inside Frame ---------------------------------------------------- f_dat = ttk.Frame(tab_dat) f_dat.pack_propagate(0) f_dat.pack(padx=0, pady=55) # --- variables ------------------------------------------------------- days = ["{:0>2d}".format(n + 1) for n in range(31)] months = [ 'JAN', 'FEV', 'MAR', 'ABR', 'MAI', 'JUN', 'JUL', 'AGO', 'SET', 'OUT', 'NOV', 'DEC' ] years = [n + 1 for n in range(2012, datetime.now().year)] self.date_all = IntVar() # --- Labels ---------------------------------------------------------- dat_l1 = Label(f_dat, text="De", bg=bg, fg=fg) dat_l2 = Label(f_dat, text="/", bg=bg, fg=fg) dat_l3 = Label(f_dat, text="/", bg=bg, fg=fg) dat_l4 = Label(f_dat, text="a", bg=bg, fg=fg) dat_l5 = Label(f_dat, text="/", bg=bg, fg=fg) dat_l6 = Label(f_dat, text="/", bg=bg, fg=fg) dat_l7 = Label(f_dat, text=" ", bg=bg, fg=fg) dat_l1.grid(row=1, column=0, pady=5, padx=5) dat_l2.grid(row=1, column=2, pady=5, padx=0) dat_l3.grid(row=1, column=4, pady=5, padx=0) dat_l4.grid(row=1, column=6, pady=5, padx=2) dat_l5.grid(row=1, column=8, pady=5, padx=0) dat_l6.grid(row=1, column=10, pady=5, padx=0) dat_l7.grid(row=1, column=12, pady=5, padx=0) # --- Comboboxes ------------------------------------------------------ self.dat_cb1 = ttk.Combobox(f_dat, width=3, textvariable=None, values=days) self.dat_cb2 = ttk.Combobox(f_dat, width=5, textvariable=None, values=months) self.dat_cb3 = ttk.Combobox(f_dat, width=4, textvariable=None, values=years) self.dat_cb4 = ttk.Combobox(f_dat, width=3, textvariable=None, values=days) self.dat_cb5 = ttk.Combobox(f_dat, width=5, textvariable=None, values=months) self.dat_cb6 = ttk.Combobox(f_dat, width=4, textvariable=None, values=years) self.dat_cb1.grid(row=1, column=1, padx=0) self.dat_cb2.grid(row=1, column=3, padx=0) self.dat_cb3.grid(row=1, column=5, padx=0) self.dat_cb4.grid(row=1, column=7, padx=0) self.dat_cb5.grid(row=1, column=9, padx=0) self.dat_cb6.grid(row=1, column=11, padx=0) # --- Separator ------------------------------------------------------- dat_s = ttk.Separator(f_dat, orient=HORIZONTAL) dat_s.grid(row=2, columnspan=13, sticky=EW, pady=5, padx=5) # --- Radiobuttons ---------------------------------------------------- dat_rb1 = Radiobutton(f_dat, text='Todas', variable=self.date_all, value=1, bg=bg, fg=fg) dat_rb1.grid(row=3, column=0, columnspan=6, pady=5, padx=5) dat_rb2 = Radiobutton(f_dat, text='Mais Recentes', variable=self.date_all, value=0, bg=bg, fg=fg) dat_rb2.grid(row=3, column=6, columnspan=5, pady=5, padx=5) dat_rb1.deselect() dat_rb2.select() # LOCALIZAÇÃO ADMINISTRATIVA TAB ###################################### # --- Main Frame ------------------------------------------------------ tab_pol = ttk.Frame(n) n.add(tab_pol, text='Localização Administrativa') # --- inside Frame ---------------------------------------------------- f_pol = ttk.Frame(tab_pol) f_pol.pack_propagate(0) f_pol.pack(padx=0, pady=40) # --- Labels ---------------------------------------------------------- pol_l1 = Label(f_pol, text="Cod Postal", bg=bg, fg=fg) pol_l2 = Label(f_pol, text="Localidade", bg=bg, fg=fg) pol_l3 = Label(f_pol, text="Concelho", bg=bg, fg=fg) pol_l4 = Label(f_pol, text="Distrito", bg=bg, fg=fg) pol_l1.grid(row=2, column=0, padx=5, pady=5) pol_l2.grid(row=3, column=0, padx=5, pady=5) pol_l3.grid(row=4, column=0, padx=5, pady=5) pol_l4.grid(row=5, column=0, padx=5, pady=5) # --- Entries --------------------------------------------------------- self.pol_e1 = Entry(f_pol) self.pol_e2 = Entry(f_pol) self.pol_e3 = Entry(f_pol) self.pol_e4 = Entry(f_pol) self.pol_e1.grid(row=2, column=1) self.pol_e2.grid(row=3, column=1) self.pol_e3.grid(row=4, column=1) self.pol_e4.grid(row=5, column=1) # LOCALIZAÃÇÃO FÍSICA TAB ############################################# # --- Main Frame ------------------------------------------------------ tab_fis = ttk.Frame(n) n.add(tab_fis, text='Localização Física') # --- inside Frame ---------------------------------------------------- f_fis = ttk.Frame(tab_fis) f_fis.pack_propagate(0) f_fis.pack(padx=5, pady=10) # --- Labels ---------------------------------------------------------- fis_l1 = Label(f_fis, text="Círculo", bg=bg, fg=fg, font=font) fis_l2 = Label(f_fis, text="Latitude", bg=bg, fg=fg) fis_l3 = Label(f_fis, text="Longitude", bg=bg, fg=fg) fis_l4 = Label(f_fis, text="Raio (Kms)", bg=bg, fg=fg) fis_l5 = Label(f_fis, text="Quadrado", bg=bg, fg=fg, font=font) fis_l6 = Label(f_fis, text="Latitude 1", bg=bg, fg=fg) fis_l7 = Label(f_fis, text="Longitude 1", bg=bg, fg=fg) fis_l8 = Label(f_fis, text="Latitude 2", bg=bg, fg=fg) fis_l9 = Label(f_fis, text="Longitude 2", bg=bg, fg=fg) fis_l1.grid(row=1, column=0, columnspan=4, padx=5, pady=0) fis_l2.grid(row=2, column=0, padx=5, pady=5) fis_l3.grid(row=2, column=2, padx=5, pady=5) fis_l4.grid(row=3, column=0, padx=5, pady=5) fis_l5.grid(row=5, column=0, columnspan=4, padx=5, pady=0) fis_l6.grid(row=6, column=0, padx=5, pady=5) fis_l7.grid(row=6, column=2, padx=5, pady=5) fis_l8.grid(row=7, column=0, padx=5, pady=5) fis_l9.grid(row=7, column=2, padx=5, pady=5) # --- Entries --------------------------------------------------------- self.fis_e1 = Entry(f_fis, width=18) self.fis_e2 = Entry(f_fis, width=18) self.fis_e3 = Entry(f_fis, width=18) self.fis_e4 = Entry(f_fis, width=18) self.fis_e5 = Entry(f_fis, width=18) self.fis_e6 = Entry(f_fis, width=18) self.fis_e7 = Entry(f_fis, width=18) self.fis_e1.grid(row=2, column=1) self.fis_e2.grid(row=2, column=3) self.fis_e3.grid(row=3, column=1) self.fis_e4.grid(row=6, column=1) self.fis_e5.grid(row=6, column=3) self.fis_e6.grid(row=7, column=1) self.fis_e7.grid(row=7, column=3) # --- Separator ------------------------------------------------------- fis_s = ttk.Separator(f_fis, orient=HORIZONTAL) fis_s.grid(row=4, columnspan=4, sticky=EW, pady=5, padx=5) # EXCEL KMZ READY TAB ################################################# # --- Main Frame ------------------------------------------------------ tab_kmz = ttk.Frame(n) n.add(tab_kmz, text='Excel KMZ') # --- inside Frame ---------------------------------------------------- f_kmz = ttk.Frame(tab_kmz) f_kmz.pack_propagate(0) f_kmz.pack(padx=25, pady=25) # --- Labels ---------------------------------------------------------- kmz_l1 = Label(f_kmz, text="Icons", bg=bg, fg=fg, font=font) kmz_l2 = Label(f_kmz, text="Nº Icon", bg=bg, fg=fg) kmz_l3 = Label(f_kmz, text="Escala", bg=bg, fg=fg) kmz_l4 = Label(f_kmz, text="Cor", bg=bg, fg=fg) kmz_l5 = Label(f_kmz, text=" ", bg=bg, fg=fg) kmz_l6 = Label(f_kmz, text="Polígonos", bg=bg, fg=fg, font=font) kmz_l7 = Label(f_kmz, text="Raio", bg=bg, fg=fg) kmz_l8 = Label(f_kmz, text="Altitude", bg=bg, fg=fg) kmz_l9 = Label(f_kmz, text="Cor", bg=bg, fg=fg) kmz_l1.grid(row=1, column=0, columnspan=6, padx=5, pady=5) kmz_l2.grid(row=2, column=0, padx=5, pady=5) kmz_l3.grid(row=2, column=2, padx=5, pady=5) kmz_l4.grid(row=2, column=4, padx=5, pady=5) kmz_l5.grid(row=2, column=6, padx=5, pady=5) kmz_l6.grid(row=5, column=0, columnspan=6, padx=5, pady=5) kmz_l7.grid(row=6, column=0, padx=5, pady=5) kmz_l8.grid(row=6, column=2, padx=5, pady=5) kmz_l9.grid(row=6, column=4, padx=5, pady=5) # --- Entries --------------------------------------------------------- self.kmz_e1 = Entry(f_kmz, width=3) self.kmz_e2 = Entry(f_kmz, width=3) self.kmz_e3 = Entry(f_kmz) self.kmz_e4 = Entry(f_kmz, width=3) self.kmz_e5 = Entry(f_kmz, width=3) self.kmz_e6 = Entry(f_kmz) self.kmz_e1.grid(row=2, column=1) self.kmz_e2.grid(row=2, column=3) self.kmz_e3.grid(row=2, column=5) self.kmz_e4.grid(row=6, column=1) self.kmz_e5.grid(row=6, column=3) self.kmz_e6.grid(row=6, column=5) # --- Separator ------------------------------------------------------- kmz_s = ttk.Separator(f_kmz, orient=HORIZONTAL) kmz_s.grid(row=4, columnspan=7, sticky=EW, pady=5, padx=5)
def __init__(self, master, player1_var, player2_var): self.master = master self.player1_var = player1_var self.player2_var = player2_var master.title('Welcome to Connect Four') master.configure(background='white') label_player1 = Label(master, text="Player 1: ", font=("Helvetica", 16), background='white', fg='black') player1_manual = Radiobutton(master, text='Manual', variable=player1_var, value=1) player1_manual.select() player1_ai1 = Radiobutton(master, text='Easy AI', variable=player1_var, value=2) player1_ai1.deselect() player1_ai2 = Radiobutton(master, text='Normal AI', variable=player1_var, value=3) player1_ai2.deselect() player1_ai3 = Radiobutton(master, text='Hard AI', variable=player1_var, value=4) player1_ai3.deselect() label_player1.grid(row=0) player1_manual.grid(column=1, row=0) player1_ai1.grid(column=2, row=0) player1_ai2.grid(column=3, row=0) player1_ai3.grid(column=4, row=0) # labeling player 2 menu label_player2 = Label(master, text="Player 2: ", font=("Helvetica", 16), background='white', fg='black') # creating player 2 menu, including player2_manual = Radiobutton(master, text='Manual', variable=player2_var, value=1) player2_manual.select() player2_ai1 = Radiobutton(master, text='Easy AI', variable=player2_var, value=2) player2_ai1.deselect() player2_ai2 = Radiobutton(master, text='Normal AI', variable=player2_var, value=3) player2_ai2.deselect() player2_ai3 = Radiobutton(master, text='Hard AI', variable=player2_var, value=4) player2_ai3.deselect() # player 2 menu locating label_player2.grid(row=1) player2_manual.grid(column=1, row=1) player2_ai1.grid(column=2, row=1) player2_ai2.grid(column=3, row=1) player2_ai3.grid(column=4, row=1) # creating button = Button(master, text="GO!", command=self._start_game) button.grid(row=3)
class GUI: def __init__(self, master): self.master = master master.title("Simulator Hodgkin-Huxley model") self.main_label = Label(master, text="Simulator Hodgkin-Huxley model") self.label_parameters = Label(master, text="Parameters") self.label_empty1 = Label(master, text="") self.label_empty2 = Label(master, width=5, text="") self.label_empty3 = Label(master, text="") self.label_empty4 = Label(master, width=15, text="") self.label_empty5 = Label(master, width=5, text="") self.label_empty6 = Label(master, text="") self.label_empty7 = Label(master, text="") self.label_empty8 = Label(master, text="") self.label_capacitance = Label(master, text="Membrane capacitance (uF/cm^2)") self.label_NaConductance = Label(master, text="gNa conductance (mS/cm^2)") self.label_KConductance = Label(master, text="gK conductance (mS/cm^2)") self.label_LConductance = Label(master, text="gL conductance (mS/cm^2)") self.label_NaPotential = Label(master, text="ENa potential (mV)") self.label_KPotential = Label(master, text="EK potential (mV)") self.label_LPotential = Label(master, text="EL potential (mV)") self.txt_capacitance = Entry(master, width=6) self.txt_NaConductance = Entry(master, width=6) self.txt_KConductance = Entry(master, width=6) self.txt_LConductance = Entry(master, width=6) self.txt_NaPotential = Entry(master, width=6) self.txt_KPotential = Entry(master, width=6) self.txt_LPotential = Entry(master, width=6) self.label_settings = Label(master, text="Settings") self.label_startTime = Label(master, text="Start time (ms)") self.label_endTime = Label(master, text="End time (ms)") self.label_inCurrent = Label(master, text="In current (uA/cm^2)") self.label_aux1 = Label(master, text="Start time stimulus (ms)") self.label_aux2 = Label(master, text="End time stimulus (ms)") self.label_currentType = Label(master, text="Stimulus current") self.txt_startTime = Entry(master, width=6) self.txt_endTime = Entry(master, width=6) self.txt_inCurrent = Entry(master, width=6) self.txt_aux1 = Entry(master, width=6) self.txt_aux2 = Entry(master, width=6) self.button_simulate = Button(master, width=20, text="Simulate", command=self.simular) self.button_defaultParameters = Button( master, width=33, text="Set default parameters", command=self.setDefaultParameters) self.button_defaultSettings = Button(master, width=33, text="Set test settings", command=self.setDefaultSettings) self.button_clean = Button(master, width=6, text="Clean", command=self.clean) self.button_helping = Button(master, width=6, text="Help", command=self.helping) self.button_close = Button(master, width=6, text="Close", command=self.close) #Ingresar componentes dentro del grid self.main_label.grid(row=0, columnspan=7) self.label_empty1.grid(row=1, columnspan=7) self.label_empty2.grid(column=0, rowspan=11) self.label_empty3.grid(row=3, columnspan=7) self.label_empty4.grid(column=3, rowspan=11) self.label_empty5.grid(column=6, rowspan=11) self.label_empty6.grid(row=13, columnspan=7) self.label_empty7.grid(row=14, columnspan=4) self.label_empty8.grid(row=12, columnspan=7) self.label_parameters.grid(row=2, column=1, columnspan=2) self.label_capacitance.grid(row=4, column=1) self.label_NaConductance.grid(row=5, column=1) self.label_KConductance.grid(row=6, column=1) self.label_LConductance.grid(row=7, column=1) self.label_NaPotential.grid(row=8, column=1) self.label_KPotential.grid(row=9, column=1) self.label_LPotential.grid(row=10, column=1) self.txt_capacitance.grid(column=2, row=4) self.txt_NaConductance.grid(column=2, row=5) self.txt_KConductance.grid(column=2, row=6) self.txt_LConductance.grid(column=2, row=7) self.txt_NaPotential.grid(column=2, row=8) self.txt_KPotential.grid(column=2, row=9) self.txt_LPotential.grid(column=2, row=10) self.label_settings.grid(row=2, column=4, columnspan=2) self.label_startTime.grid(row=4, column=4) self.label_endTime.grid(row=5, column=4) self.label_inCurrent.grid(row=6, column=4) self.label_aux1.grid(row=10, column=4) self.label_aux2.grid(row=11, column=4) self.label_currentType.grid(row=8, column=4) self.txt_startTime.grid(row=4, column=5) self.txt_endTime.grid(row=5, column=5) self.txt_inCurrent.grid(row=6, column=5) self.txt_aux1.grid(row=10, column=5) self.txt_aux2.grid(row=11, column=5) self.button_simulate.grid(row=15, column=1) self.button_clean.grid(row=15, column=3) self.button_helping.grid(row=15, column=4) self.button_close.grid(row=15, column=5) self.button_defaultParameters.grid(row=13, column=1, columnspan=2) self.button_defaultSettings.grid(row=13, column=4, columnspan=2) self.windowGraphics = None self.guiGraphics = None self.master.protocol("WM_DELETE_WINDOW", self.on_closing) self.var = IntVar() self.radioBDiscrete = Radiobutton(master, text="Discrete", variable=self.var, value=1, command=self.selectDiscrete) self.radioBContinuous = Radiobutton(master, text="Continuous", variable=self.var, value=2, command=self.selectContinuous) self.radioBIncrement = Radiobutton(master, text="Increase", variable=self.var, value=3, command=self.selectIncrement) self.radioBDiscrete.select() self.radioBContinuous.deselect() self.radioBIncrement.deselect() self.radioBDiscrete.grid(row=7, column=5) self.radioBContinuous.grid(row=8, column=5) self.radioBIncrement.grid(row=9, column=5) def simular(self): validation1 = True validation1 = validation1 and self.txt_capacitance.get() != "" validation1 = validation1 and self.txt_NaConductance.get() != "" validation1 = validation1 and self.txt_KConductance.get() != "" validation1 = validation1 and self.txt_LConductance.get() != "" validation1 = validation1 and self.txt_NaPotential.get() != "" validation1 = validation1 and self.txt_KPotential.get() != "" validation1 = validation1 and self.txt_LPotential.get() != "" validation1 = validation1 and self.txt_startTime.get() != "" validation1 = validation1 and self.txt_endTime.get() != "" validation1 = validation1 and self.txt_inCurrent.get() != "" if (self.var.get() == 1 or self.var.get() == 3): validation1 = validation1 and self.txt_aux1.get() != "" validation1 = validation1 and self.txt_aux2.get() != "" if (validation1 == True): validation2 = True validation2 = validation2 and self.isFloat( self.txt_capacitance.get()) validation2 = validation2 and self.isFloat( self.txt_NaConductance.get()) validation2 = validation2 and self.isFloat( self.txt_KConductance.get()) validation2 = validation2 and self.isFloat( self.txt_LConductance.get()) validation2 = validation2 and self.isFloat( self.txt_NaPotential.get()) validation2 = validation2 and self.isFloat( self.txt_KPotential.get()) validation2 = validation2 and self.isFloat( self.txt_LPotential.get()) validation2 = validation2 and self.isFloat( self.txt_startTime.get()) validation2 = validation2 and self.isFloat(self.txt_endTime.get()) validation2 = validation2 and self.isFloat( self.txt_inCurrent.get()) if (self.var.get() == 1 or self.var.get() == 3): validation2 = validation2 and self.isFloat(self.txt_aux1.get()) validation2 = validation2 and self.isFloat(self.txt_aux2.get()) if (validation2 == True): if (float(self.txt_startTime.get()) < 0.0 or float(self.txt_endTime.get()) < float( self.txt_startTime.get()) or float(self.txt_inCurrent.get()) < 0.0): messagebox.showinfo("Error", "There are no valid data") else: validation3 = False if (self.var.get() == 1): #discreto if (float(self.txt_aux1.get()) < float( self.txt_startTime.get()) or float(self.txt_aux2.get()) > float( self.txt_endTime.get()) or float(self.txt_aux1.get()) == float( self.txt_aux2.get()) or float(self.txt_aux1.get()) > float( self.txt_aux2.get())): messagebox.showinfo("Error", "There are no valid data") else: validation3 = True if (self.var.get() == 3): #aumento if (float(self.txt_aux1.get()) < 0.0 or float(self.txt_aux2.get()) < 0.0 or float(self.txt_aux2.get()) >= float( self.txt_endTime.get())): messagebox.showinfo("Error", "There are no valid data") else: validation3 = True if (self.var.get() == 2): #continuo validation3 = True if (validation3 == True): self.plot() else: messagebox.showinfo("Error", "There are no valid data") else: messagebox.showinfo("Error", "There are empty fields") def isFloat(self, n): try: n1 = float(n) except (ValueError, TypeError): return False else: return True def plot(self): C_m = float(self.txt_capacitance.get()) g_Na = float(self.txt_NaConductance.get()) g_K = float(self.txt_KConductance.get()) g_L = float(self.txt_LConductance.get()) E_Na = float(self.txt_NaPotential.get()) E_K = float(self.txt_KPotential.get()) E_L = float(self.txt_LPotential.get()) tI = float(self.txt_startTime.get()) tF = float(self.txt_endTime.get()) cI = float(self.txt_inCurrent.get()) if (self.var.get() == 1 or self.var.get() == 3): aux1 = float(self.txt_aux1.get()) aux2 = float(self.txt_aux2.get()) else: aux1 = -1 aux2 = -1 if (self.windowGraphics != None): self.windowGraphics.quit() self.windowGraphics.destroy() self.windowGraphics = Tk() self.guiGraphics = guiGraphics(self.windowGraphics, C_m, g_Na, g_K, g_L, E_Na, E_K, E_L, tI, tF, cI, aux1, aux2, self.var.get()) self.windowGraphics.mainloop() self.windowGraphics = None def setDefaultParameters(self): self.txt_capacitance.delete(0, 'end') self.txt_capacitance.insert(0, 1.0) self.txt_NaConductance.delete(0, 'end') self.txt_NaConductance.insert(0, 120.0) self.txt_KConductance.delete(0, 'end') self.txt_KConductance.insert(0, 36.0) self.txt_LConductance.delete(0, 'end') self.txt_LConductance.insert(0, 0.3) self.txt_NaPotential.delete(0, 'end') self.txt_NaPotential.insert(0, 50.0) self.txt_KPotential.delete(0, 'end') self.txt_KPotential.insert(0, -77.0) self.txt_LPotential.delete(0, 'end') self.txt_LPotential.insert(0, -54.387) def setDefaultSettings(self): self.txt_startTime.delete(0, 'end') self.txt_startTime.insert(0, 0) self.txt_endTime.delete(0, 'end') self.txt_endTime.insert(0, 100.0) self.txt_inCurrent.delete(0, 'end') self.txt_inCurrent.insert(0, 10.0) self.txt_aux1.delete(0, 'end') self.txt_aux2.delete(0, 'end') if (self.var.get() == 1): self.txt_aux1.insert(0, 40.0) self.txt_aux2.insert(0, 50.0) else: if (self.var.get() == 3): self.txt_aux1.insert(0, 3.0) self.txt_aux2.insert(0, 20.0) def clean(self): self.txt_capacitance.delete(0, 'end') self.txt_NaConductance.delete(0, 'end') self.txt_KConductance.delete(0, 'end') self.txt_LConductance.delete(0, 'end') self.txt_NaPotential.delete(0, 'end') self.txt_KPotential.delete(0, 'end') self.txt_LPotential.delete(0, 'end') self.txt_startTime.delete(0, 'end') self.txt_endTime.delete(0, 'end') self.txt_inCurrent.delete(0, 'end') self.txt_aux1.delete(0, 'end') self.txt_aux2.delete(0, 'end') if (self.windowGraphics != None): self.windowGraphics.quit() self.windowGraphics.destroy() def helping(self): subprocess.Popen("helping.pdf", shell=True) def close(self): self.master.quit() self.master.destroy() def on_closing(self): self.master.quit() self.master.destroy() def selectDiscrete(self): self.txt_aux1.grid() self.txt_aux2.grid() self.label_aux1.grid() self.label_aux2.grid() self.txt_aux1.delete(0, 'end') self.txt_aux2.delete(0, 'end') self.label_aux1.config(text='Start time stimulus (ms)') self.label_aux2.config(text='End time stimulus (ms)') def selectContinuous(self): self.txt_aux1.delete(0, 'end') self.txt_aux2.delete(0, 'end') self.txt_aux1.grid_remove() self.txt_aux2.grid_remove() self.label_aux1.grid_remove() self.label_aux2.grid_remove() def selectIncrement(self): self.txt_aux1.grid() self.txt_aux2.grid() self.label_aux1.grid() self.label_aux2.grid() self.txt_aux1.delete(0, 'end') self.txt_aux2.delete(0, 'end') self.label_aux1.config(text='Current increase (uA/cm^2)') self.label_aux2.config(text='Every (ms)')