def update_vars_from_rec(self): # for each tk var set it to current rec_obj var value self.timestamp_label.config(text="timestamp: {}".format(self.rec.timestamp)) self.layer_label.config(text="layer: {}".format(self.rec.layer)) if self.rec.activate: self.activate_cb.select() else: self.activate_cb.deselect() self.playback_var.set(self.rec.playback_control) self.loop_type_var.set(self.rec.lp_type) self.speed_var.set(str(self.rec.speed)) self.control_speed_var.set(str(self.rec.control_speed)) self.qp_choices = [-1] + [str(i) for i,x in enumerate(self.rec.clip.vars['qp']) if x is not None] self.qp_var.set(str(self.rec.qp_to_activate)) self.lp_var_l.set(str(self.rec.lp_to_select[0])) self.lp_var_r.set(str(self.rec.lp_to_select[1])) for chooser in [self.qp_chooser,self.lp_chooser_l,self.lp_chooser_r]: chooser['menu'].delete(0,'end') for choice in self.qp_choices: self.qp_chooser['menu'].add_command(label=choice, command=tk._setit(self.qp_var, choice)) self.lp_chooser_l['menu'].add_command(label=choice, command=tk._setit(self.lp_var_l, choice)) self.lp_chooser_r['menu'].add_command(label=choice, command=tk._setit(self.lp_var_r, choice)) # pats self.update_pat_choices()
def load_new_tables(self): '''Opens a file chooser dialog so that the user can choose table files to load. Loads these into dicts.''' file_opts = {"defaultextension": ".csv", "title": "Choose table file(s)", } filenames = filedialog.askopenfilenames(**file_opts) for f in filenames: table_name = f[f.rfind('/')+1:f.rfind('.csv')] try: self.tables[table_name] = load_table(f) except TableFormatError as err: mbox.showwarning("Open file", "Bad formatting: {}".format(err.err_msg)) return except csvError: mbox.showwarning("Open file", "Cannot open file: Bad CSV input.") return except FileNotFoundError: mbox.showwarning("Open file", "Cannot open file: File not found.") return # Update the options in self.table_menu. new_comm = tk._setit(self.chosen_table, table_name) self.table_menu['menu'].add_command(label=table_name, command=new_comm)
def update_pat_choices(self): self.pattern_selector['menu'].delete(0,'end') pattern_choices = [-1] + [str(i) for i in range(len(self.rec.pats))] for choice in pattern_choices: self.pattern_selector['menu'].add_command(label=choice, command=tk._setit(self.pattern_choice, choice)) self.pattern_choice.set(str(self.rec.cur_pat)) self.update_pat_buts()
def refresh_option_menu(option_menu, var, new_options): """http://stackoverflow.com/a/17581364/1817465""" option_menu['menu'].delete(0, 'end') # Insert list of new options (tk._setit hooks them up to var) for choice in new_options: option_menu['menu'].add_command(label=choice, command=tkinter._setit(var, choice))
def update_launchables(self, new_launchables): self.select_trans_l['menu'].delete(0,'end') if len(new_launchables) > 0: for i in new_launchables: self.select_trans_l['menu'].add_command(label=str(i), command=tk._setit(self.var_select, str(i))) self.var_select.set(new_launchables[0]) else: self.var_select.set("...")
def copy_midi(*args): self.value.set(self.parent.deviceselect.tested_inp.get()) self.typeselect['menu'].delete(0,tk.END) if len(self.parent.deviceselect.tested_inp_ns.get().split(',')) < 3: self.keytype.set(type_opts[0]) else: for type in type_opts: self.typeselect['menu'].add_command(label=type, command=tk._setit(self.keytype, type))
def tmp_reload_options(selected_profile_name=None): profile["menu"].delete(0, END) for profile_name in sorted(self.preferences.get_profiles(tab)): if not selected_profile_name: selected_profile_name = profile_name profile["menu"].add_command(label=profile_name, command=tkinter._setit(profile_var, profile_name, tmp_select)) profile_var.set(selected_profile_name) tmp_select(selected_profile_name)
def update_list(self, processes): """ Update Plist """ self.var.set('') self.menu['menu'].delete(0, 'end') for item in processes: self.menu['menu'].add_command(label=item, command=tk._setit(self.var, item))
def serverchange(self,arg1,arg2,arg3): dir = './data/' + self.serverVar.get() temp = [] for x in os.listdir(dir): if os.path.isfile(dir +'/'+ x): temp.append(x) self.classDropdown['menu'].delete(0,'end') for s in temp: self.classDropdown['menu'].add_command(label=s,command=TK._setit(self.classVar,s))
def id_midi(*args): res = self.parent.configmidi.id_midi() if not res: return self.value.set(res[0]) self.typeselect['menu'].delete(0,tk.END) if len(res[1]) < 3: self.keytype.set(type_opts[0]) else: for type in type_opts[1:]: self.typeselect['menu'].add_command(label=type, command=tk._setit(self.keytype, type))
def refreshOptionMenu(self, startEntry): # Delete old options self.idParentEntry['menu'].delete(0, 'end') # Insert list of new options (tk._setit hooks them up to var) self.currentIDList = self.writer.getAllIDs() for choice in self.currentIDList: self.idParentEntry['menu'].add_command(label=choice, command=tk._setit(self.idParent, choice)) self.idParent.set(startEntry)
def update_file_choices(self): self.list_files['menu'].delete(0, 'end') files = [] if self.files_list_hook is not None: files = self.files_list_hook() new_files = sorted([i for i in files if '*'+i not in self.file_buffer] + list(self.file_buffer.keys())) for f in new_files: self.list_files['menu'].add_command(label=f, command=_setit(self.selected_file, f)) return new_files
def SetMenu(self,valueList,value=None): """ clear and reload the menu with a new set of options. valueList - list of new options value - initial value to set the optionmenu's menubutton to """ self['menu'].delete(0,'end') for item in valueList: self['menu'].add_command(label=item, command=_setit(self.variable,item,self.command)) if value: self.variable.set(value)
def opendb(self): filename = askopenfilename() if not filename == "": self.dbfilename = filename self.dbfilename_label["text"] = os.path.basename(filename) self.coursevar.set("-- Please choose --") self.table_box["menu"].delete(0, "end") tables = get_result.get_courses(filename) for choice in tables: self.table_box['menu'].add_command(label=choice, command=tk._setit(self.coursevar, choice))
def refrescar(símismo, opciones, texto_opciones=None): símismo.opciones = opciones if texto_opciones is None: texto_opciones = opciones símismo.MenúOpciones['menu'].delete(0, 'end') símismo.conv = {'': ''} for op, tx in zip(opciones, texto_opciones): símismo.conv[op] = tx símismo.MenúOpciones['menu'].add_command(label=tx, command=tk._setit(símismo.var, tx)) símismo.borrar()
def show_summary(self): """ Show the details of the selected package """ try: curr_item = self.multi_items_list.scroll_tree.focus() item_dict = self.multi_items_list.scroll_tree.item(curr_item) selected_module = 'Module Name : {}'.format(item_dict['values'][0]) available_version = 'Version : {}'.format(item_dict['values'][1]) module_summary = 'Summary : {}'.format(item_dict['values'][2]) home_page = 'Home Page : {}'.format(item_dict['values'][3]) last_updated = 'Last Updated : {}'.format(item_dict['values'][4]) selected_package_details = '{}\n{}\n{}\n{}\n{}'.format( selected_module, available_version, module_summary, home_page, last_updated,) self.package_details.configure(state='normal') self.package_details.delete(1.0, 'end') self.package_details.insert(1.0, selected_package_details) self.package_details.configure(state='disabled') #search for module name in self.search_results new_options = [] for items in self.search_results: if items[0]==item_dict['values'][0]: self.module_details = items for x in items[5:]: new_options.append(x[0]) new_options = tuple(new_options) #Update compatibility options in option menu self.option_menu.config(state='normal') self.option_menu['menu'].delete(0,'end') #update options menu for opt_tag in new_options: self.option_menu['menu'].add_command( label=opt_tag, command=tk._setit(self.options_var, opt_tag)) except Exception as e: print (e) self.package_details.configure(state='normal') self.package_details.delete(1.0, 'end') self.package_details.insert(1.0, 'No module selected') self.package_details.configure(state='disabled')
def field_update(self, option): sub_industries = [] sub_industries.append('All') for industry in self.industries: if industry['name'] == option: for sub_industry in industry['list']: sub_industries.append(sub_industry) self.sub_industry_dropdown_default.set(sub_industries[0]) self.sub_industry_dropdown['menu'].delete(0, "end") for sub_industry in sub_industries: self.sub_industry_dropdown['menu'].add_command(label=sub_industry, command=tkinter._setit(self.sub_industry_dropdown_default, sub_industry))
def cars(self): self.connectMySQL() typeList=[] cursor = self.db.cursor() sql ="SELECT DISTINCT type FROM car_information" cursor.execute(sql) for item in cursor: typeList.append(item) self.typeList=typeList counter=0 for item in self.typeList: print (item) self.OMCar['menu'].insert('end','command', label=item[0], command=_setit(self.Type, item[0])) counter+=1 self.db.close()
def places(self): db = self.connectMySQL() placeList=[] cursor = self.db.cursor() sql ="SELECT DISTINCT location_name FROM location" cursor.execute(sql) for item in cursor: placeList.append(item) self.placeList=placeList counter=0 for item in self.placeList: print (item) self.OMLocation['menu'].insert('end','command', label=item[0], command=_setit(self.Location, item[0])) counter+=1 self.db.close()
def setupOutputList(self): if (self.audioDevice != None and self.type == "input"): if (self.selectOutput != None): self.selectOutput['menu'].delete(0, 'end') for outputDev in [str(d.id) + " " + d.name for d in self.device.outputDevices if d.hostapi == self.audioDevice.hostapi]: self.selectOutput['menu'].add_command(label=outputDev, command=tk._setit(self.selectOutputValue, outputDev)) else: self.selectOutputValue = tk.StringVar() self.selectOutputValue.set("No Output") self.selectOutput = tk.OptionMenu(self, self.selectOutputValue, *[str(d.id) + " " + d.name for d in self.device.outputDevices if d.hostapi == self.audioDevice.hostapi], command=self.changeOutput) self.selectOutput.grid(row=3, columnspan=2, sticky="ew") self.selectOutput.config(width=8)
def update_anchor(self, words): """ Update anchors with selected words :param: selected words :type: basestring """ self.clean_anchor() for choice in words: phrase = '' for term in choice: phrase = phrase + term[0] + ' ' if not phrase in self._dicword: self._dicword[phrase] = choice else: continue import tkinter as tk self._w['menu'].add_command(label=phrase, command=tk._setit(self.phrases, phrase))
def field_update(self, option): # Hide 'All agencies' checkbox if option != 'Industry Focus (Agy only)': self.companies_text.config(state='normal') self.industry_dropdown.config(state='normal') self.field_agy_checkbox_val.set(0) self.field_agy_checkbox.place(x=-350, y=30) else: self.companies_text.config(state='disabled') self.industry_dropdown.config(state='disabled') self.field_agy_checkbox_val.set(1) self.field_agy_checkbox.place(x=self.left_align+350, y=30) self.industries = self.redbooks_extractor.get_industries_adv_filter(option) self.industry_dropdown_default.set(self.industries[0]) self.industry_dropdown['menu'].delete(0, "end") for industry in self.industries: self.industry_dropdown['menu'].add_command(label=industry, command=tkinter._setit(self.industry_dropdown_default, industry))
def refresh_names(self): global names self.menuvar.set('') self.dropdown['menu'].delete(0, 'end') for name in names: self.dropdown['menu'].add_command(label=name, command=tk._setit(self.menuvar, name))
def selectMultiImage(opt_menu, menu_var): global img_list, current_slide, slide_caption, slide_control_panel filetype = [("images", "*.jpg *.jpeg *.png")] path_list = filedialog.askopenfilenames(title="Choose atleast 5 images", filetypes=filetype) if (len(path_list) < 5): messagebox.showerror("Error", "Choose atleast 5 images.") else: img_list = [] current_slide = -1 # Resetting slide control panel if (slide_control_panel != None): slide_control_panel.destroy() # Creating Image list for path in path_list: img_list.append(cv2.imread(path)) # Creating choices for profile pic menu menu_var.set("") opt_menu['menu'].delete(0, 'end') for i in range(len(img_list)): ch = "Image " + str(i + 1) opt_menu['menu'].add_command(label=ch, command=tk._setit(menu_var, ch)) menu_var.set("Image 1") # Creating slideshow of images img_size = left_frame.winfo_height() - 200 current_slide += 1 showImage(img_list[current_slide], img_size) slide_control_panel = tk.Frame(left_frame, bg="#202d42", pady=20) slide_control_panel.pack() back_img = tk.PhotoImage(file="previous.png") next_img = tk.PhotoImage(file="next.png") prev_slide = tk.Button(slide_control_panel, image=back_img, bg="#202d42", bd=0, highlightthickness=0, activebackground="#202d42", command=lambda: getNewSlide("prev")) prev_slide.image = back_img prev_slide.grid(row=0, column=0, padx=60) slide_caption = tk.Label(slide_control_panel, text="Image 1 of {}".format(len(img_list)), fg="#ff9800", bg="#202d42", font="Arial 15 bold") slide_caption.grid(row=0, column=1) next_slide = tk.Button(slide_control_panel, image=next_img, bg="#202d42", bd=0, highlightthickness=0, activebackground="#202d42", command=lambda: getNewSlide("next")) next_slide.image = next_img next_slide.grid(row=0, column=2, padx=60)
def addOptionsToOptionList(l=[]): om_selected_var.set('') om['menu'].delete(0,'end') for choice in l: om['menu'].add_command(label=choice,command=tk._setit(om_selected_var,choice)) om_selected_var.set(l[0])
def CompanyAnimate(i): global REFRESH_COT_FLG,CompanyDF,CompareCompanyDF,COMPANY_SELECT_FLG,COMPARE_COMPANY_VAL,COMPARE_COMPANY_FLG global COMPANY_PRODUCT_FLG,CompanyProductDF,COMPANY_PRODUCT_VAL,COMPANY_PRODUCT_PLOT,COMPARE_SELECT_FLG try: if REFRESH_COT_FLG is True: ax1 = f.add_subplot(221) ax1.clear() #plot basic chart for all products or the company specific products if selected ExplodeListProduct=[] for i in range(0,len(pd.unique(CompanyDF.Product))): if i%2==0: ExplodeListProduct.append(0.1) else: ExplodeListProduct.append(0) #plot Pie chart for Products ax1.pie(CompanyDF.ComplaintId.groupby([CompanyDF.Product]).count(), explode=tuple(ExplodeListProduct), labels=pd.unique(CompanyDF.Product),shadow=True,autopct='%1.1f%%', startangle=90) CompanyName='' if len(pd.unique(CompanyDF.Company)) == 1: CompanyName=str(pd.unique(CompanyDF.Company)[0])+' Products' else: CompanyName='All Company Products' ax1.set_title(CompanyName) if COMPANY_SELECT_FLG is True: var2.set('Select Product') CompanyProductChoice['menu'].delete(0,END) CompanyProductChoice['menu'].add_command(label='None', command=tk._setit(var2, 'None')) for choice in pd.unique(CompanyDF.Product): CompanyProductChoice['menu'].add_command(label=choice, command=tk._setit(var2, choice)) COMPANY_SELECT_FLG=False if COMPARE_SELECT_FLG is True: #create a dataframe #print('set for compare company') CompareList=[] CompareList.append(var2.get()) #print(CompareList) CompareCompanyDF=FilteredDF[FilteredDF.Product.isin(CompareList)] var3.set('Select Company') CompareCompanyChoice['menu'].delete(0,END) CompareCompanyChoice['menu'].add_command(label='None', command=tk._setit(var3, 'None')) for choice in pd.unique(CompareCompanyDF.Company): CompareCompanyChoice['menu'].add_command(label=choice, command=tk._setit(var3, choice)) COMPARE_SELECT_FLG=False #code to display the product issues is company Product is selected ax2=f.add_subplot(222) if COMPANY_PRODUCT_FLG is True: ax2.clear() CompanyProductList=[] CompanyProductList.append(COMPANY_PRODUCT_VAL) CompanyProductDF=CompanyDF[ (CompanyDF.Product.isin(CompanyProductList)) ] ExplodeListCompanyProductIssue=[] for i in range(0,len(pd.unique(CompanyProductDF.Issue))): if i%2==0: ExplodeListCompanyProductIssue.append(0.1) else: ExplodeListCompanyProductIssue.append(0) #plot Pie chart for Products ax2.pie(CompanyProductDF.ComplaintId.groupby([CompanyProductDF.Issue]).count(), explode=tuple(ExplodeListCompanyProductIssue), labels=pd.unique(CompanyProductDF.Issue),shadow=True,autopct='%1.1f%%', startangle=90) CompanyName='' if len(pd.unique(CompanyProductDF.Product)) == 1: CompanyName=str(pd.unique(CompanyProductDF.Product)[0])+' Issues' else: CompanyName='Product Not Specified' ax2.set_title(CompanyName) COMPANY_PRODUCT_PLOT=True COMPANY_PRODUCT_FLG=False else: if COMPANY_PRODUCT_PLOT is False: f.delaxes(ax2) #code to add compare Company if COMPARE_COMPANY_FLG is True: ax3=f.add_subplot(223) ax3.clear() #Plot issues of the compare company CompareList=[] CompareList.append(COMPARE_COMPANY_VAL) CompareDF=CompareCompanyDF[ (CompareCompanyDF.Company.isin(CompareList)) ] ExplodeListCompareIssue=[] for i in range(0,len(pd.unique(CompareDF.Issue))): if i%2==0: ExplodeListCompareIssue.append(0.1) else: ExplodeListCompareIssue.append(0) ax3.pie(CompareDF.ComplaintId.groupby([CompareDF.Issue]).count(), explode=tuple(ExplodeListCompareIssue), labels=pd.unique(CompareDF.Issue),shadow=True,autopct='%1.1f%%', startangle=90) CompareName='Company :'+COMPARE_COMPANY_VAL ax3.set_title(CompareName) #Plot compare of the compare company Company1=var.get() Company2=var3.get() CompanyLists=[] CompanyLists.append(Company1) CompanyLists.append(Company2) #print(CompanyLists) ax4=f.add_subplot(224) ax4.clear() PlotDF=CompareCompanyDF[CompareCompanyDF.Company.isin(CompanyLists)] ExplodeCompare=[] for i in range(0,len(pd.unique(PlotDF.Company))): if i%2==0: ExplodeCompare.append(0.1) else: ExplodeCompare.append(0) #PlotDF.Issue.groupby([PlotDF.Company,PlotDF.Issue]).count().plot(kind='bar') ax4.pie(PlotDF.Issue.groupby([PlotDF.Company]).count(), explode=tuple(ExplodeCompare), labels=pd.unique(PlotDF.Company),shadow=True,autopct='%1.1f%%', startangle=90) ax4.set_title('Comparison') COMPARE_COMPANY_FLG=False except Exception as e: print(e)
def ouvrirEtape(self,etape): self.frameEtape.labelNom.config(text=self.listeEtape[etape]["nom"]) taches=self.listeEtape[etape]["taches"] self.frameEtape.etape=etape for tache in taches: self.frameEtape.listboxTaches.insert(END,tache["nom"]) for membre in self.parent.modele.getListeMembres(self.id): self.frameEtape.optionMenuMembres['menu'].add_command(label=membre, command=tk._setit(self.frameEtape.membres, membre)) self.swapper(self.frameEtape)
"""increase RC after every row""" row_counter+=1 """an extra line for readablity""" Label(master, text='', bg='#FFE100').grid(row=row_counter) """increase RC after every row""" row_counter+=1 """add a launch place""" option = StringVar() option.set('Anywhere Else') menu = Menubutton(master, text='Select a site') opt = OptionMenu(menu, option, 'Anywhere Else') menu.menu = opt['menu'] for i in places.keys(): menu.menu.add_command(label=i, command=tk._setit(option, i)) menu['menu'] = menu.menu menu.config(fg='#FFE100', bg='black', cursor='crosshair', relief='raised') menu.grid(row=row_counter, column=0) menu_label = Label(master, text=option.get(), bg='black', fg='#FFE100', width=17) menu_label.text = option.get() menu_label.grid(row=row_counter, column=1) """increase RC after every row""" row_counter+=1 """label and entry for longitude and latitude""" Label(master, bg='#FFE100', text='Observer Latitude, Longitude (decimal degrees):').grid(row=row_counter) lat_i = Entry(master, bg='black', fg='#FFE100') lat_i.grid(row=row_counter, column=1)
def updateUsers(): varUserSelected.set('') option['menu'].delete(0,END) newUserList = library.getAllUsers() for user in newUserList: option['menu'].add_command(label=user, command=tkinter._setit(varUserSelected, user))
def new_file(self): self.list_files['menu'].add_command(label=self.defaultname.format(self.fsettings.get('extension', '.mln')), command=_setit(self.selected_file, self.defaultname.format(self.fsettings.get('extension', '.mln')))) self.selected_file.set(self.defaultname.format(self.fsettings.get('extension', '.mln'))) self.file_buffer[self.defaultname.format(self.fsettings.get('extension', '.mln'))] = '' self.editor.delete("1.0", END) self.dirty = True
def setChoices(self, choices): self.var.set("Results") self["menu"].delete(0, "end") for c in choices: self["menu"].add_command(label=c, command=tk._setit(self.var, c))
def clear_midi(*args): self.value.set('[-,-]'), self.keytype.set('----') self.typeselect['menu'].delete(0,tk.END) for type in type_opts: self.typeselect['menu'].add_command(label=type, command=tk._setit(self.keytype, type))
offsetList = [] for ofst in range(-120, 145, 5): offsetList.append(ofst / 10.0) tzOffsetLabel = ttk.Label(tab3, text='Time Zone Offset from UTC') tzOffsetLabel.grid(column=0, row=5, padx=5, pady=5, sticky=tk.W) tzOffsetValue = ttk.OptionMenu(tab3, tz, "0", *offsetList) tzOffsetValue.grid(column=1, row=5, padx=0, pady=5, sticky=tk.W) saveButton = ttk.Button(tab3, text='Save', command=saveSettings) saveButton.grid(column=1, row=6, padx=0, pady=5, sticky=tk.W) # ================================================================================== exitButton = tk.Button(r, text='Exit', width=25, command=exitTimer) exitButton.pack() getSettings() try: with open(activityListFileName) as classActivity: activityList = json.load(classActivity) classActivities['menu'].delete(0,'end') for activity_item in activityList: classActivities['menu'].add_command(label=activity_item, command=tk._setit(activity, activity_item)) activity.set(activityList[0]) except: messagebox.showerror("Error", "Activity List file missing") displayTime() r.mainloop()
def updateMenu(self, logins): self.option['menu'].delete(0, 'end') for choice in logins: self.option['menu'].add_command(label=choice, command=tk._setit(self.variable, choice[0]))