def initUI(self): self.parent.title("Buttons") self.style = Style() self.style.theme_use("default") frame = Frame(self, relief=GROOVE, borderwidth=5) frame.pack(fill=BOTH, expand=1) self.pack(fill = BOTH, expand = 1) self.imageLabel = Label(frame, image = "") self.imageLabel.pack(fill=BOTH, expand=1) closeButton = Button(self, text="Close") closeButton.pack(side=RIGHT) okButton = Button(self, text="OK") okButton.pack(side=RIGHT) options = [item for item in dir(cv2.cv) if item.startswith("CV_CAP_PROP")] option = OptionMenu(self, self.key, *options) self.key.set(options[0]) option.pack(side="left") spin = Spinbox(self, from_=0, to=1, increment=0.05) self.val = spin.get() spin.pack(side="left")
def __init__(self, parent, variable=None, values=None, **kwargs): if values is None: values = [] self._var = variable or StringVar() OptionMenu.__init__(self, parent, self._var, *values, **kwargs) if values: self._var.set(values[0])
def build_word(self): row = Frame(self.exportWord, width=30) row.pack(side=RIGHT) row_font = Frame(row, width=30) row_font.pack() lst1 = OPTIONS self.var1 = StringVar() self.var1.set(OPTIONS[1]) self.font_name_box = OptionMenu(row_font, self.var1, *lst1) self.font_name_box.config(width=28) self.font_name_box.pack() row_size = Frame(row, width=30) row_size.pack() lst2 = OPTIONS_SIZE self.var2 = StringVar() self.var2.set(OPTIONS_SIZE[-1]) self.font_size_box = OptionMenu(row_font, self.var2, *lst2) self.font_size_box.config(width=28) self.font_size_box.pack() row_button = Frame(row, width=30) row_button.pack() button_export = Button(row_button, width=30, height=2, text="EXPORT", command=self.choose_file_name) button_export.pack()
def propertieswidgets(self, frame, row, master, chemical_list, formula_list, MW_list): self.master = master self.chemical_list = chemical_list self.formula_list = formula_list self.MW_list = MW_list self.middlelabel = Label(frame, width=8, justify='center', text=' || ') self.delwidget = Button(frame, width=5, justify='center', text='Delete', command=self.del_product) self.namewidget = OptionMenu(frame, self.name, *chemical_list, command=self.click_name) self.coefwidget = Entry(frame, width=8, justify='center', textvariable=self.coef) self.fwidget = Entry(frame, width=8, justify='center', textvariable=self.formula, font='Calibri 11') self.middlelabel.grid(row=row, column=5, padx=2, pady=1, sticky='WE') self.delwidget.grid(row=row, column=6, padx=2, pady=1) self.coefwidget.grid(row=row, column=7, padx=2, pady=1) self.namewidget.grid(row=row, column=8, padx=2, pady=1, sticky='WE') self.fwidget.grid(row=row, column=9, padx=2, pady=1, sticky='WE')
def __init__(self, pvapp, top): """ Constructor """ self.pvapp = pvapp Frame.__init__(self, top) self.pack(expand=True) # if user resizes, expand Frame self.pack(fill='both') self.focus_set() # get the focus self.grab_set() # make this window modal self['bg'] = 'black' # set black background self['padx'] = '15' # pad sides with 15 points self['pady'] = '5' # pad top/bottom 5 points self.master.title('PVmodule') # set title bar self.SPlogoLabel = Label(self, image=self.pvapp.SPlogo, cnf={'borderwidth': '0'}) self.SPlogoLabel.pack({'side': 'top'}) self.numberCells = IntVar(self) # bind numberCells self.numberCells.set(MODULE_SIZES[0]) # default value # pylint: disable = W0142 self.numberCellsOption = OptionMenu(self, self.numberCells, *MODULE_SIZES) # pylint: enable = W0142 self.numberCellsOption.pack({'side': 'top', 'fill': 'both'}) self.QUIT = Button(self, cnf={'text': 'Quit', 'command': self.quit}) self.QUIT.pack({'side': 'top', 'fill': 'both'})
class VelocitySelect(Frame): VELOCITIES = [speeds.kmh, speeds.mih, speeds.ms] def __init__(self, **kwargs): master = None if 'master' not in kwargs else kwargs['master'] Frame.__init__(self, master) Label(text='Output Velocity').grid(row=0, column=0, sticky=W, in_=self) self.vel = VelocitySelect.VELOCITIES[0] self.vel_selected = StringVar() vel_opts = [ '%s (%s)' % (sp.name, sp.symbol) for sp in VelocitySelect.VELOCITIES ] self.velopt = OptionMenu(self, self.vel_selected, *vel_opts) self.vel_selected.set('%s (%s)' % (self.vel.name, self.vel.symbol)) self.velopt.grid(row=0, column=1, sticky=W) def val(self, val=None): if val is not None: self.vel.value = val else: sel = self.vel_selected.get().split()[0] for v in VelocitySelect.VELOCITIES: if sel in v.name: self.vel = v return self.vel
def create_order_type(self, master, previous_row=-1, previous_column=-1): order_type_lbl = Label(master, text="Entry Type:") order_type_lbl.grid(row=previous_row + 1, column=previous_column + 1, sticky=E, padx=(3, 0)) order_type_lbl.config(bg=background_colour, fg=label_font_colour) self.is_entry_market = True def change_order_type(*args): self.is_entry_market = (self.order_type.get() == "Market Buy \/") self.order_type = StringVar() self.order_type.trace( "w", change_order_type ) # Reduces how much work is done when the pump starts choices = {"Market Buy \/", "Limit Buy \/"} self.entry_type_option_menu = OptionMenu(master, self.order_type, *choices) self.entry_type_option_menu.grid(row=previous_row + 1, column=previous_column + 2, sticky=W + E, padx=8) self.entry_type_option_menu.config(highlightthickness=0) self.entry_type_option_menu.configure(indicatoron=0) self.order_type.set("Market Buy \/")
class Example(Frame): def __init__(self, master): Frame.__init__(self, master) self.dict = { 'Asia': ['Japan', 'China', 'India'], 'Europe': ['Portugal', 'Switzerland', 'Ukraine'] } self.var_a = StringVar(self) self.var_b = StringVar(self) self.var_a.trace('w', self.update_options) self.option_menu_a = OptionMenu(self, self.var_a, *self.dict.keys()) self.option_menu_a.pack(side="top") self.option_menu_a["width"] = 10 self.option_menu_b = OptionMenu(self, self.var_b, '') self.option_menu_b["width"] = 10 self.option_menu_b.pack(side="top") self.var_a.set('Asia') def update_options(self, *args): countries = self.dict[self.var_a.get()] self.var_b.set(countries[0]) menu = self.option_menu_b['menu'] menu.delete(0, 'end') for c in countries: menu.add_command(label=c, command=lambda x=c: self.var_b.set(x))
class WheelEntry(LabelFrame): DIA_UNITS = [dist.mm, dist.cm, dist.inch] def __init__(self, **kwargs): master = None if 'master' not in kwargs else kwargs['master'] LabelFrame.__init__(self, master, text='Wheel') self.unitopts = ['%s (%s)' % (x.name, x.symbol) for x in WheelEntry.DIA_UNITS] self.__val = WheelEntry.DIA_UNITS[0] self.createSpin() self.create_unit_opts() def create_unit_opts(self): self.unitoptselected = StringVar() self.unitoptselected.set(self.unitopts[2]) self.unitopt = OptionMenu(self, self.unitoptselected, *self.unitopts) self.unitopt.grid(row=1, column=1, in_=self) self.val() def val(self, val=None): if val is not None: self.__val.value = val else: sel = self.unitoptselected.get().split()[0] for u in WheelEntry.DIA_UNITS: if sel in u.name: self.__val = u self.__val.value = int(self.Spin.val.get()) return self.__val def createSpin(self): self.Spin = LabeledSpin(title='Dia') self.Spin.val.set(27) self.Spin.Spin.config(from_=10, to=1000, width=4) self.Spin.grid(row=1, column=0, in_=self)
def __init__(self, image): self.original = image self.image = image.copy() self.window = Tk() self.genViews() self.currentView = StringVar(self.window) self.currentView.set('Original') options = self.filters.keys() options.sort() self.views = OptionMenu(self.window, self.currentView, *options, command=self.applyFilter) self.views.pack() self.tkImage = ImageTk.PhotoImage(image) self.lblImage = Label(image=self.tkImage) self.lblImage.bind('<Button-1>', self.displayInfos) self.lblImage.bind('<Button-3>', self.save) self.lblImage.image = self.tkImage self.lblImage.pack() self.status = StringVar() self.lblStatus = Label(textvariable=self.status, justify='right') self.lblStatus.pack() self.window.mainloop()
def __initUI(self): """ Initialize UI with two entry fields and a connection button.""" self.parent.title('Connect to a Sudoku server') self.pack(fill=BOTH, expand=1) Label(self, text='Enter Nickname').grid(row=0, padx=(15, 0)) Label(self, text='Nickname presets').grid(row=1, padx=(15, 0)) Label(self, text='Enter Sudoku server port').grid(row=2, padx=(15, 0)) self.entry_nickname = Entry(self) self.entry_nickname.grid(row=0, column=1, padx=(0, 15)) var = StringVar(self) var.set('') self.entry_nickname_options = OptionMenu(self, var, 'Peeter', 'Jürka', 'Antskan', 'Jüri', 'Toss', command=self.__select_preset) self.entry_nickname_options.grid(row=1, column=1, padx=(0, 15)) self.entry_port = Entry(self) self.entry_port.grid(row=2, column=1, padx=(0, 15)) self.submit_name = Button(self, text='Submit and connect', command=self.__submit_connect) self.submit_name.grid(row=3, column=1)
def create_fee_type(self, master, previous_row=-1, previous_column=-1): fee_type_lbl = Label(master, text="Fee Type:") fee_type_lbl.grid(row=previous_row + 1, column=previous_column + 1, sticky=E, padx=(3, 0)) fee_type_lbl.config(bg=background_colour, fg=label_font_colour) self.is_using_bnb = True def change_fee_type(*args): self.is_using_bnb = ( self.order_type.get() == "Binance Coin (BNB) \/") self.fee_type = StringVar() self.fee_type.trace( "w", change_fee_type ) # Reduces how much work is done when the pump starts choices = {"Binance Coin (BNB) \/", "0.1% Of All Trades \/"} self.fee_type_option_menu = OptionMenu(master, self.fee_type, *choices) self.fee_type_option_menu.grid(row=previous_row + 1, column=previous_column + 2, sticky=W + E, padx=8) self.fee_type_option_menu.config(highlightthickness=0) self.fee_type_option_menu.configure(indicatoron=0) self.fee_type.set("Binance Coin (BNB) \/")
def populateAxesFrame(self, master): master.grid_columnconfigure(0, weight=1) row = 0 col = 0 w = Label(master, text='X axis:', anchor=W) w.grid(row=row, column=col, sticky=NSEW) row += 1 var = self.XAxis = StringVar(value='...') w = self.wXAxes = OptionMenu(master, var, var.get()) w.config(anchor=W) w.grid(row=row, column=col, sticky=NSEW) self.rowXAxes = row self.colXAxes = col row += 1 w = Label(master, text='Y axis:', anchor=W) w.grid(row=row, column=col, sticky=NSEW) row += 1 var = self.YAxis = StringVar(value='...') w = self.wYAxes = OptionMenu(master, var, var.get()) w.config(anchor=W) w.grid(row=row, column=col, sticky=NSEW) self.rowYAxes = row self.colYAxes = col
def convertChoice(self): #Las partes que integran el primer submenu llamado "DE", labelFrame,menu, entrada. self.labelFrameFrom=LabelFrame(self.master,text="De",background=R.Bgcolor) self.labelFrameFrom.grid(row=1,column=0,padx=5,pady=3) self.menuFrom=OptionMenu(self.labelFrameFrom,self.fromLabel,"",) self.menuFrom.configure(bg=R.White,fg=R.Black,activebackground=R.hoverBtnColor,highlightbackground=R.Bgcolor, indicatoron=0,image=self.btnFlechaimg, compound='right') self.menuFrom.grid(row=0,column=0,padx=3,pady=2,sticky=E) self.entryFrom=Entry(self.labelFrameFrom,justify='center',textvariable=self.fromNumber) self.entryFrom.grid(row=2,column=0,padx=5,pady=5) #Las partes que integran el segundo submenu llamado "Hasta", labelFrame, menu, entrada. self.labelFrameTo=LabelFrame(self.master,text="Hacia",background=R.Bgcolor) self.labelFrameTo.grid(row=1,column=1,padx=5,pady=3) self.menuTo=OptionMenu(self.labelFrameTo,self.toLabel,"",) self.menuTo.configure(bg=R.White,fg=R.Black, activebackground=R.hoverBtnColor,highlightbackground=R.Bgcolor, indicatoron=0,image=self.btnFlechaimg, compound='right') self.menuTo.grid(row=0,column=0, padx=3, pady=2, sticky=E) self.entryTo=Entry(self.labelFrameTo,justify='center',textvariable=self.toNumber,state="readonly") self.entryTo.configure(bg="red", readonlybackground=R.Bgcolor) self.entryTo.grid(row=2,column=0,padx=3,pady=5)
class ModuleMenu(Frame): def __init__(self, master, module_dict): Frame.__init__(self, master) self.moduleDict = module_dict self.department = StringVar(self) self.module = StringVar(self) self.department.trace('w', self.update_options) keys = self.moduleDict.keys() keys.sort() self.departmentMenu = OptionMenu(self, self.department, *keys) self.moduleMenu = OptionMenu(self, self.module, '') self.department.set('None') self.departmentMenu.grid(row=1, column=1) self.moduleMenu.grid(row=1, column=2) self.pack() def update_options(self, *args): module_values = self.moduleDict[self.department.get()] self.module.set(module_values[0]) menu = self.moduleMenu['menu'] menu.delete(0, 'end') for module_value in module_values: menu.add_command(label=module_value) def get_module_code(self): return (self.module.get().split(' - '))[0]
def populateAxes(self, fields): text = '' for field in fields: text += ('\n' if len(text) > 0 else '') + field self.wFields['text'] = text # +++++++++++++++++++++++++++++++++++++++++++ old_menu = self.wXAxes row = self.rowXAxes col = self.colXAxes old_menu.grid_forget() var = self.XAxis = StringVar(value='...') w = self.wXAxes = OptionMenu(old_menu.master, var, *fields) w.config(anchor=W) w.grid(row=row, column=col, sticky=NSEW) # +++++++++++++++++++++++++++++++++++++++++++ old_menu = self.wYAxes row = self.rowYAxes col = self.colYAxes old_menu.grid_forget() var = self.YAxis = StringVar(value='...') w = self.wYAxes = OptionMenu(old_menu.master, var, *fields) w.config(anchor=W) w.grid(row=row, column=col, sticky=NSEW)
def __addMenuOption(self, key, label, defaultOption, optionsLists): """ :param key: Key that represent the option (this should be unique) :param label: Name for identify the tag and/or options :param defaultOption: Default option :param optionsLists: List of options that will had the menu """ defaultOptionString = StringVar(self) defaultOptionString.set(defaultOption) frame = Frame(self, border=3) frame.pack(fill=X) Label(frame, text=label, anchor=E, width=18).pack(side=LEFT) # OptionMenu is similar to dropdown list box where user can expand and # select one of the several available options. # Replace the use of apply: Reference: https://stackoverflow.com/a/45739449 menuOptions = OptionMenu(*(frame, defaultOptionString) + tuple(optionsLists)) menuOptions['width'] = 12 menuOptions['anchor'] = W menuOptions.pack(side=LEFT) # Added the StringVar and his key in the dictionary options self.__options[key] = defaultOptionString
class VelocitySelect(Frame): VELOCITIES = [speeds.kmh, speeds.mih, speeds.ms] def __init__(self, **kwargs): master = None if 'master' not in kwargs else kwargs['master'] Frame.__init__(self, master) Label(text='Output Velocity').grid(row=0, column=0, sticky=W, in_=self) self.vel = VelocitySelect.VELOCITIES[0] self.vel_selected = StringVar() vel_opts = ['%s (%s)' % (sp.name, sp.symbol) for sp in VelocitySelect.VELOCITIES] self.velopt = OptionMenu(self, self.vel_selected, *vel_opts) self.vel_selected.set('%s (%s)' % (self.vel.name, self.vel.symbol)) self.velopt.grid(row=0, column=1, sticky=W) def val(self, val=None): if val is not None: self.vel.value = val else: sel = self.vel_selected.get().split()[0] for v in VelocitySelect.VELOCITIES: if sel in v.name: self.vel = v return self.vel
def cs_dropd(root, r, c, options, action=None, drop_conf={}, grid_conf={}): startvalue = StringVar() startvalue.set('') # options[0] dropdown = OptionMenu(root, startvalue, **drop_conf) dropdown.grid(row=r, column=c, **grid_conf) if action is not None: startvalue.trace('w', action) return startvalue, dropdown
def __init__(self, parent_frame, label_text, value, *values): super(LabelOption, self).__init__(parent_frame, label_text) self._option_default = value self._option_var = StringVar(value=value) self._option = OptionMenu(self._label_frame, self._option_var, *values) #self._option.pack(side=LEFT, fill=X) self._option.pack(side=RIGHT, fill=X, anchor=E)
def __init__(self, master, variable, value, *values, **kwargs): kwargsCopy = copy.copy(kwargs) if 'highlightthickness' in kwargs.keys(): del kwargs['highlightthickness'] OptionMenu.__init__(self, master, variable, value, *values, **kwargs) self.config(highlightthickness=kwargsCopy.get('highlightthickness')) self.variable = variable self.command = kwargs.get('command')
def __draw_new_draft_window(self, parent): self.parent.title("New Draft") style = StringVar() style.set("Snake") opponent_label = Label(parent, text="Opponents") opponent_entry = Entry(parent, width=5) position_label = Label(parent, text="Draft Position") position_entry = Entry(parent, width=5) rounds_label = Label(parent, text="Number of Rounds") rounds_entry = Entry(parent, width=5) style_label = Label(parent, text="Draft Style") style_menu = OptionMenu(parent, style, "Snake", "Linear") def begin_draft(): """ initializes variables to control the flow of the draft calls the first window of the draft. """ self.game.number_of_opponents = int(opponent_entry.get()) self.game.draft_position = int(position_entry.get()) self.game.number_of_rounds = int(rounds_entry.get()) self.game.draft_style = style.get() self.game.opponents = [] self.game.current_position = 1 self.game.current_round = 1 for x in xrange(self.game.number_of_opponents): self.game.opponents.append(Opponent.Opponent(x)) if self.game.draft_position <= self.game.number_of_opponents + 1: MainUI(self.parent, self.game) else: tkMessageBox.showinfo("Error", "Draft position too high!\nYou would never get to pick a player" ) def begin_button(event): begin_draft() ok_button = Button(parent, text="OK", command=begin_draft) self.parent.bind("<Return>", begin_button) opponent_label.grid(row=0, pady=5) opponent_entry.grid(row=0, column=1, pady=5) position_label.grid(row=1) position_entry.grid(row=1, column=1) rounds_label.grid(row=2, pady=5) rounds_entry.grid(row=2, column=1, pady=5, padx=5) style_label.grid(row=3) style_menu.grid(row=3, column=1) ok_button.grid(row=4, column=1, sticky="se", pady=5, padx=5)
def __init__(self, master, variable, value, *values, **kwargs): #get a copy of kwargs before OptionMenu.__init__ munges them kwargsCopy=copy.copy(kwargs) if 'highlightthickness' in kwargs.keys(): del(kwargs['highlightthickness']) OptionMenu.__init__(self, master, variable, value, *values, **kwargs) self.config(highlightthickness = kwargsCopy.get('highlightthickness')) self.variable = variable self.command = kwargs.get('command')
def body(self, master): Label(master, text='Current Type: ').grid(row=0,column=0) Label(master, text=self.current_type).grid(row=0,column=1) Label(master, text='Change: ').grid(row=1,column=0) self.option_val = StringVar(master) self.option_val.set(self.current_type) om = OptionMenu (master, self.option_val, 'master','slave','master+slave') om.grid(row=1,column=1,sticky=W) return om # initial focus on menu
def body(self, master): Label(master, text='Current Type: ').grid(row=0, column=0) Label(master, text=self.current_type).grid(row=0, column=1) Label(master, text='Change: ').grid(row=1, column=0) self.option_val = StringVar(master) self.option_val.set(self.current_type) om = OptionMenu(master, self.option_val, 'master', 'slave', 'master+slave') om.grid(row=1, column=1, sticky=W) return om # initial focus on menu
def click_tortuosity(self, event=None): """Give the default tortuosity model corresponding to the selected layer type.""" #try: if event != 1: self.tort.set(self.tort_types[self.types.index(self.type.get())]) self.tortwidget = OptionMenu(self.frame, self.tort, *self.torts) self.tortwidget.grid_forget() self.tortwidget.grid(row=4, column=3, padx=2, pady=1, sticky='WE')
def initUIElements(self): filePaths = self.fileGroup.getResourcePaths() self.var = StringVar(self) if filePaths: self.var.set(filePaths[0]) self.fileMenu = OptionMenu(self,self.var,*filePaths) else: self.fileMenu = OptionMenu(self,self.var,()) if self.active: self.select = Button(self,text="Browse",command=self.onSelect)
def __init__(self, master, variable, value, *values, **kwargs): # TODO copy value instead of whole dict kwargsCopy=copy.copy(kwargs) if 'highlightthickness' in kwargs.keys(): del(kwargs['highlightthickness']) OptionMenu.__init__(self, master, variable, value, *values, **kwargs) self.config(highlightthickness=kwargsCopy.get('highlightthickness')) #self.menu=self['menu'] self.variable=variable self.command=kwargs.get('command')
def init3Voices(self): # [(47, 67), (52, 76), (60, 81)]) # (B,2) - 20 # (E,3) - 24 # (C,4) - 25 self.note_name = ['C','Cs','D','Ds','E','F','Fs','G','Gs','A','As','B'] self.pitchC1 = StringVar() self.pitchC2 = StringVar() self.pitchC3 = StringVar() self.octave1 = IntVar() self.octave2 = IntVar() self.octave3 = IntVar() self.range1 = IntVar() self.range2 = IntVar() self.range3 = IntVar() v1Label =Label(self, text="Voice 1 start:") v1Label.place(x = 30, y = 25) self.w1 = OptionMenu(self, self.pitchC1, *self.note_name) self.w1.place(x = 135, y = 25) self.pitchC1.set(self.note_name[11]) self.oc1 = OptionMenu(self, self.octave1, *range(1, 9)) self.oc1.place(x=200, y=25) self.octave1.set(2) v1_rangeLabel = Label(self, text="Range:") v1_rangeLabel.place(x=300, y=25) self.rangeoption1 = OptionMenu(self, self.range1, *range(18, 26)) self.rangeoption1.place(x=360, y=25) self.range1.set(20) v2Label = Label(self, text="Voice 2 start:") v2Label.place(x=30, y=50) self.w2 = OptionMenu(self, self.pitchC2, *self.note_name) self.w2.place(x=135, y=50) self.pitchC2.set(self.note_name[4]) self.oc2 = OptionMenu(self, self.octave2, *range(1, 9)) self.oc2.place(x=200, y=25 * 2) self.octave2.set(3) v2_rangeLabel = Label(self, text="Range:") v2_rangeLabel.place(x=300, y=25 * 2) self.rangeoption2 = OptionMenu(self, self.range2, *range(18, 26)) self.rangeoption2.place(x=360, y=25 * 2) self.range2.set(24) v3Label = Label(self, text="Voice 3 start:") v3Label.place(x=30, y=75) self.w3 = OptionMenu(self, self.pitchC3, *self.note_name) self.w3.place(x=135, y=75) self.pitchC3.set(self.note_name[0]) self.oc3 = OptionMenu(self, self.octave3, *range(1, 9)) self.oc3.place(x=200, y=25 * 3) self.octave3.set(4) v3_rangeLabel = Label(self, text="Range:") v3_rangeLabel.place(x=300, y=25 * 3) self.rangeoption3 = OptionMenu(self, self.range3, *range(18, 26)) self.rangeoption3.place(x=360, y=25 * 3) self.range3.set(25)
def _init_corpus_select(self, parent): innerframe = Frame(parent, background=self._BACKGROUND_COLOUR) self.var = StringVar(innerframe) self.var.set(self.model.DEFAULT_CORPUS) Label(innerframe, justify=LEFT, text=' Corpus: ', background=self._BACKGROUND_COLOUR, padx = 2, pady = 1, border = 0).pack(side='left') other_corpora = self.model.CORPORA.keys().remove(self.model.DEFAULT_CORPUS) om = OptionMenu(innerframe, self.var, self.model.DEFAULT_CORPUS, command=self.corpus_selected, *self.model.non_default_corpora()) om['borderwidth'] = 0 om['highlightthickness'] = 1 om.pack(side='left') innerframe.pack(side='top', fill='x', anchor='n')
def __init__(self, parent): Frame.__init__(self, parent) self.parent = parent training_error_laber = Label(self, text = 'Training Error: ') training_error_laber.pack(side = 'left') error_options = [round(0.1 + i*0.1, 2) for i in range(25)] self.selected_error = DoubleVar(self, value = DEFAULT_TRAINING_ERROR) option_menu = OptionMenu(self, self.selected_error, *error_options, command = self._on_error_selection) option_menu.pack(side = 'right')
def __init__(self, parent): Frame.__init__(self, parent) self.parent = parent max_iteration_laber = Label(self, text = 'Max iteration: ') max_iteration_laber.pack(side = 'left') max_iteration_options = [500 + i*500 for i in range(15)] self.selected_maximum = IntVar(self, value = DEFAULT_MAX_ITERATIONS) option_menu = OptionMenu(self, self.selected_maximum, *max_iteration_options, command = self._on_maximum_selection) option_menu.pack(side = 'right')
def __init__(self, **kwargs): master = None if 'master' not in kwargs else kwargs['master'] Frame.__init__(self, master) Label(text='Output Velocity').grid(row=0, column=0, sticky=W, in_=self) self.vel = VelocitySelect.VELOCITIES[0] self.vel_selected = StringVar() vel_opts = [ '%s (%s)' % (sp.name, sp.symbol) for sp in VelocitySelect.VELOCITIES ] self.velopt = OptionMenu(self, self.vel_selected, *vel_opts) self.vel_selected.set('%s (%s)' % (self.vel.name, self.vel.symbol)) self.velopt.grid(row=0, column=1, sticky=W)
def __init__(self,parent,items,callback=None,current=None,*args,**kwargs): Frame.__init__(self,parent,*args,**kwargs) self.var = StringVar(self) self.items = items if current in self.items: self.var.set(current) self.var.trace("w", lambda x,y,z,v=self.var: self.onChoice()) self.delete = None self.choice = None self.callback = callback self.listeners = [] self.menu = OptionMenu(self,self.var,*([i.name for i in self.items]+["None"])) self.menu.configure(width=10)
def wybierajZestawZnakow(zestawieZnakow): gui = Tk() gui.resizable(0, 0) gui.title("") fra1 = LabelFrame(gui, text="Stary zestaw znaków") fra1.pack(padx=2, pady=2) var1 = StringVar() var1.set(zestawieZnakow[0]) opt1 = OptionMenu(fra1, var1, *zestawieZnakow) opt1.pack(fill="x") but1 = Button(fra1, text="Otwieraj plik", command=lambda: gui.destroy()) but1.pack(fill="x", padx=2, pady=2) gui.mainloop() return var1.get()
def __init__(self, parent): Frame.__init__(self, parent) self.parent = parent training_error_laber = Label(self, text='Training Error: ') training_error_laber.pack(side='left') error_options = [round(0.1 + i * 0.1, 2) for i in range(25)] self.selected_error = DoubleVar(self, value=DEFAULT_TRAINING_ERROR) option_menu = OptionMenu(self, self.selected_error, *error_options, command=self._on_error_selection) option_menu.pack(side='right')
def __init__(self, parent): Frame.__init__(self, parent) self.parent = parent max_iteration_laber = Label(self, text='Max iteration: ') max_iteration_laber.pack(side='left') max_iteration_options = [500 + i * 500 for i in range(15)] self.selected_maximum = IntVar(self, value=DEFAULT_MAX_ITERATIONS) option_menu = OptionMenu(self, self.selected_maximum, *max_iteration_options, command=self._on_maximum_selection) option_menu.pack(side='right')
def __init__(self, parent): Frame.__init__(self, parent) self.parent = parent number_of_classes_label = Label(self, text = 'Number of classes: ') number_of_classes_label.grid(row = 0, column = 0) number_options = range(DEFAULT_NUMBER_OF_CLASS, MAX_NUMBER_OF_CLASSES+1) self.selected_number = IntVar(self, value = DEFAULT_NUMBER_OF_CLASS) option_menu = OptionMenu(self, self.selected_number, *number_options, command = self._on_number_selection) option_menu.grid(row = 0, column = 1) self.observers = []
def add_unit_frame(self, parent=None, id=1): """! Construct the frame which is contains the widgets relating to a single data logging unit. @param self The pointer for the object @param id An identifier for use with the frame. This identifier can be an integer or string and is displayed within the label of the frame @param parent The parent frame/object to be used for the new frame. @return The data logging unit frame """ #Dictionary to encapsulate information data_dict = {} data_dict['frame'] = StdLabelFrame(parent, text='Device %s' % id) #Create dynamic components data_dict['unit'] = StringVar() data_dict['unit'].set(UNIT_TYPES[0]) data_dict['status'] = StringVar() data_dict['status'].set(CONNECTION_TYPES[0]) data_dict['reading'] = StringVar() data_dict['reading'].set('%0.2f' % 0) #Display components #Unit selection drop_down = OptionMenu(data_dict['frame'], data_dict['unit'], *UNIT_TYPES) drop_down.configure(width=MAX_WIDGET_WIDTH, bg='white', borderwidth=0, highlightbackground='white', highlightcolor='white') drop_down.grid(row=0, columnspan=2) #Connection Status StdLabel(data_dict['frame'], text='Connection Status: ').\ grid(row=1, column=0) data_dict['status_widget'] = StdLabel(data_dict['frame'], textvariable=data_dict['status'], fg='red') data_dict['status_widget'].grid(row=1, column=1) #Measurement StdLabel(data_dict['frame'], textvariable=data_dict['reading'], font=tkFont.Font(family='Arial', size=36), bg='gray').\ grid(row=2, columnspan=2, pady=20) return data_dict
class FileFrame(Frame): """ Gui frame that is tied to a FileGroup object. """ def __init__(self,parent,active=False,fileGroup=FileGroup(),\ *args,**kwargs): Frame.__init__(self,parent,*args,**kwargs) self.parent = parent self.active = active self.fileGroup = fileGroup self.initUIElements() self.gridUIElements() def initUIElements(self): filePaths = self.fileGroup.getResourcePaths() self.var = StringVar(self) if filePaths: self.var.set(filePaths[0]) self.fileMenu = OptionMenu(self,self.var,*filePaths) else: self.fileMenu = OptionMenu(self,self.var,()) if self.active: self.select = Button(self,text="Browse",command=self.onSelect) def gridUIElements(self): self.fileMenu.config(width=10) self.fileMenu.grid(row=0,column=0) if self.active: self.select.grid(row=0,column=1) def onSelect(self): menu = self.fileMenu["menu"] menu.delete(0, "end") paths = tkFileDialog.askopenfilenames(parent=self) if len(paths) > 0: map(self.fileGroup.addFile,paths) self.resetFileMenu(paths,0) def resetFileMenu(self, options, index=None): menu = self.fileMenu["menu"] menu.delete(0, "end") for string in options: command=Tkinter._setit(self.var, string, None) menu.add_command(label=string,command=command) if index is not None: self.var.set(options[index]) def getResourcePaths(self): return self.fileGroup.getResourcePaths()
def __init__(self, parent): Frame.__init__(self, parent) number_of_layers_label = Label(self, text = 'Number of layers: ') number_of_layers_label.grid(row=0, column=0) number_options = range(DEFAULT_NUMBER_OF_HIDDEN_LAYERS, MAX_NUMBER_OF_HIDDEN_LAYERS + 1) selected_number = IntVar(self, value = DEFAULT_NUMBER_OF_HIDDEN_LAYERS) option_menu = OptionMenu(self, selected_number, *number_options, command = self._on_hidden_layers_number_selection) option_menu.grid(row=0, column=1) self.observers = []
def __init__(self, master, module_dict): Frame.__init__(self, master) self.moduleDict = module_dict self.department = StringVar(self) self.module = StringVar(self) self.department.trace('w', self.update_options) keys = self.moduleDict.keys() keys.sort() self.departmentMenu = OptionMenu(self, self.department, *keys) self.moduleMenu = OptionMenu(self, self.module, '') self.department.set('None') self.departmentMenu.grid(row=1, column=1) self.moduleMenu.grid(row=1, column=2) self.pack()
def create_monitor(self): self.monitor_frame = LabelFrame(self, text="Monitor and Transport") this_cycle = Scale(self.monitor_frame, label='cycle_pos', orient=HORIZONTAL, from_=1, to=16, resolution=1) this_cycle.disable, this_cycle.enable = (None, None) this_cycle.ref = 'cycle_pos' this_cycle.grid(column=0, row=0, sticky=E + W) self.updateButton = Button(self.monitor_frame, text='Reload all Settings', command=self.request_update) self.updateButton.grid(row=1, sticky=E + W) self.ForceCaesuraButton = Button(self.monitor_frame, text='Force Caesura', command=self.force_caesura) self.ForceCaesuraButton.grid(row=2, sticky=E + W) self.saveBehaviourButton = Button(self.monitor_frame, text='Save current behaviour', command=self.request_saving_behaviour) self.saveBehaviourButton.grid(row=3, sticky=E + W) self.saveBehaviourNameEntry = Entry(self.monitor_frame) self.saveBehaviourNameEntry.grid(row=4, sticky=E + W) self.saveBehaviourNameEntry.bind('<KeyRelease>', self.request_saving_behaviour) self.selected_behaviour = StringVar() self.selected_behaviour.trace('w', self.new_behaviour_chosen) self.savedBehavioursMenu = OptionMenu(self.monitor_frame, self.selected_behaviour, None,) self.savedBehavioursMenu.grid(row=5, sticky=E + W) self.monitor_frame.grid(column=0, row=10, sticky=E + W)
def __init__(self, image): self.original = image self.image = image.copy() self.window = Tk() self.genViews() self.currentView = StringVar(self.window) self.currentView.set('Original') options = self.filters.keys();options.sort() self.views = OptionMenu(self.window, self.currentView, *options, command=self.applyFilter) self.views.pack() self.tkImage = ImageTk.PhotoImage(image) self.lblImage = Label(image=self.tkImage) self.lblImage.bind('<Button-1>', self.displayInfos) self.lblImage.bind('<Button-3>', self.save) self.lblImage.image = self.tkImage self.lblImage.pack() self.status = StringVar() self.lblStatus = Label(textvariable=self.status, justify='right') self.lblStatus.pack() self.window.mainloop()
def populateControlFrameWidgets(self, master): master.grid_columnconfigure(0, weight=1) master.grid_columnconfigure(1, weight=1) row = 0 col = 0 w = Label(master, text="Control mode: ") w.grid(row=row, column=col, sticky=NSEW) col += 1 var = self.runMode = StringVar() options = self.runModeMenuItems.values() w = self.wRunMode = OptionMenu(master, var, *options, command=self.wRunModeCB) w.config(anchor=W) w.grid(row=row, column=col, sticky=NSEW) row += 1 col = 0 w = self.wStart = Button(master, text='Start', command=self.wStartCB) w.grid(row=row, column=col, sticky=NSEW) col += 1 w = self.wFinish = Button(master, text='Finish', state=DISABLED, command=self.wFinishCB) w.grid(row=row, column=col, sticky=NSEW)
def get_box(self): if not self.dialog: from Tkinter import Tk,Listbox,Button,Scrollbar,X,Y,BOTTOM,RIGHT,HORIZONTAL,VERTICAL,OptionMenu,StringVar self.dialog = Tk() self.dialog.title("TODO") scrollbar = Scrollbar(self.dialog,orient=HORIZONTAL) yscrollbar = Scrollbar(self.dialog,orient=VERTICAL) self.todolist = Listbox(self.dialog,width=50,xscrollcommand=scrollbar.set,yscrollcommand=yscrollbar.set) scrollbar.config(command=self.todolist.xview) scrollbar.pack(side=BOTTOM,fill=X) yscrollbar.config(command=self.todolist.yview) yscrollbar.pack(side=RIGHT,fill=Y) self.todolist.pack(side="left",fill="both",expand=True) cat_list_name = StringVar() cat_list_name.set("Category") btn = Button(self.dialog,text="Refresh",command=self.refresh_list) btn.pack() self.refresh_list() if self.categories: self.cat_list = OptionMenu(self.dialog,cat_list_name,*(self.categories+["ALL","NONE"]),command=self.filter_list) self.cat_list.pack() return (self.dialog,self.todolist)
def menuChoices(self): #Menu de seleccion principal sobre los tipos que conversion que hara el programa self.MenuChoices = OptionMenu(self.master, self.selectMed, R.LongMain,R.AlmacMain, command=self.choice) self.MenuChoices.configure(bg="white",fg="black",activebackground="#eceefb",highlightbackground=R.Bgcolor, indicatoron=0,image=self.btnFlechaimg,compound='right') self.MenuChoices.grid(row=0,column=0)
def __init__(self, parent, width, height): #Call the initializer of the class we're inheriting from Frame.__init__(self, parent) self.db = SpellingDatabase() student_list_frame = Frame(self) self.student_listpane = ListPane(student_list_frame, height=30, width = 35) self.student_listpane.singleClickFunc=self.display_details sort_options_list = ['First Name', 'Last Name'] self.sort_v = StringVar() self.sort_v.set(sort_options_list[1]) self.sort_option = OptionMenu(student_list_frame, self.sort_v, *sort_options_list, command=self.update_sort) sort_label = Label(student_list_frame, text="Sort by:") title_label = Label(student_list_frame, text="Student Details") title_label.grid(row=0, column=0, sticky=W,pady=5) self.student_listpane.grid(row=1, column=0, columnspan=2) sort_label.grid(row=2, column=0, sticky=W, padx = 2) self.sort_option.grid(row=2, column=0, padx=50, sticky=W) student_details_frame=Frame(self) fname_label = Label(student_details_frame, text="First Name:") lname_label = Label(student_details_frame, text="Last Name:") age_label = Label(student_details_frame, text="Birthday:") comments_label = Label(student_details_frame, text="Comments") self.fname_entry = Entry(student_details_frame, width=30) self.lname_entry = Entry(student_details_frame, width=30) self.age_entry = Entry(student_details_frame, width=30) self.comments_text = Text(student_details_frame, width=65, height=10) enable_edit_button = Button(student_details_frame, text="Edit Details", command=self.update_student) add_student_button = Button(student_details_frame, text="Add Student", command=self.insert_student) remove_student_button = Button(student_details_frame, text="Remove Student", command=self.remove_student) fname_label.grid(row=0, column=0, sticky=W, padx=3) lname_label.grid(row=1, column=0, sticky=W, padx=3) age_label.grid(row=2, column=0, sticky=W, padx=3) comments_label.grid(row=3, column=0, sticky=W, padx=3) self.fname_entry.grid(row=0, column=1, sticky=W) self.lname_entry.grid(row=1, column=1, sticky=W) self.age_entry.grid(row=2, column=1, sticky=W) self.comments_text.grid(row=4, column=0, columnspan=2, sticky=W, padx=10) enable_edit_button.grid(row=5, column=0, padx=7) add_student_button.grid(row=5, column=1, sticky=W) remove_student_button.grid(row=5, column=1, sticky=W, padx=110) student_list_frame.pack(side=LEFT) student_details_frame.pack(side=LEFT) #Load student table from database student_records = self.db.sql("SELECT last_name, first_name From students ORDER By last_name") names_list = [] for record in student_records: names_list.append("%s, %s" % (record[0], record[1])) self.student_listpane.display(names_list)
def __init__(self, controller): # initialize the GUI self.app = Tk() self.app.title('Tic Tac Toe') self.app.resizable(width=False, height=False) self.game_controller = controller # interface to the game self.winner = None # who has won the game # make the board self.buttons = [[None for i in range(SIZE)] for j in range(SIZE)] for x in range(SIZE): for y in range(SIZE): handler = lambda x=x, y=y: self.move(x,y) # each button corresponds to making a move in that square self.buttons[x][y] = self.make_button(text='', command=handler, row=y, column=x+SIZE, width=1) # button to reset the board self.make_button(text='New Game', command=lambda:self.reset(), row=SIZE+1, column=SIZE) # button that makes the machine learn self.make_button(text='Learn', command=lambda:self.learn(), row=SIZE+1, column=SIZE+SIZE/2) # button that causes the machine to forget how to play self.make_button(text='Forget', command=lambda:self.forget(), row=SIZE+1, column=2*SIZE-1) self.update() # the score labels score = Label(self.app, text=' SCORE:', font=Font(family="Courier", weight='bold', size=32)) score.grid(row=0, column=0, columnspan=SIZE) self.score = Label(self.app, text='0', font=Font(family="Courier", weight='bold', size=32)) self.score.grid(row=1, column=1) # choose if you are X or O. X always goes first self.player_choice = StringVar() # how to keep track of the option which_player = OptionMenu(self.app, self.player_choice, *(STRINGS[X], STRINGS[O])) # options are X and O which_player.grid(row=SIZE+2, column=SIZE+2) which_player.config(font=Font(family='Courier')) self.player_choice.set('X') self.player_choice.trace('w', self.choose_player) # choose between playing against a Perfect player or Learning player self.comp_type = StringVar() # how to keep track of the option comp_type = OptionMenu(self.app, self.comp_type, *('Learning', 'Perfect')) comp_type.grid(row=SIZE+2, column=SIZE) comp_type.config(width=11, font=Font(family='Courier')) self.comp_type.set('Learning') self.comp_type.trace('w', self.choose_comp_type)
class SelectPage(BasePage): def __init__(self, parent, controller): BasePage.__init__(self, parent, controller) def setupView(self, title="Test Select Page", item_list=[], default=0): self.desc = Label(self, text=title, font=TITLE_FONT) self.desc.grid(row=0, column=0, columnspan=2) self.optVar = StringVar() self.selection = OptionMenu(self, self.optVar, *item_list) self.selection.grid(row=1, column=0, columnspan=2, sticky="WE") self.optVar.set(item_list[default]) self.ok = Button(self, text='Next', command=lambda: self.controller.transition(self)) self.ok.grid(row=2, column=1, sticky="W") self.cancel = Button(self, text='Cancel', command=lambda: self.controller.quit()) self.cancel.grid(row=2, column=0, sticky="E")
class MenuFrame(Frame): """ Drop down menu in Mapping windows __str__ must be an unique identifier """ def __init__(self,parent,items,callback=None,current=None,*args,**kwargs): Frame.__init__(self,parent,*args,**kwargs) self.var = StringVar(self) self.items = items if current in self.items: self.var.set(current) self.var.trace("w", lambda x,y,z,v=self.var: self.onChoice()) self.delete = None self.choice = None self.callback = callback self.listeners = [] self.menu = OptionMenu(self,self.var,*([i.name for i in self.items]+["None"])) self.menu.configure(width=10) def onChoice(self): if self.callback: candidates = [i for i in self.items if i.name == self.var.get()] item = None if candidates: item = candidates[0] self.choice = item else: self.delete = self.choice self.callback(item) def grid(self,*args,**kwargs): Frame.grid(self,*args,**kwargs) self.menu.grid() def get(self): return self.choice def set(self,item): if item in self.items: self.var.set(item)
def __init__(self, **kwargs): master = None if 'master' not in kwargs else kwargs['master'] Frame.__init__(self, master) Label(text='Output Velocity').grid(row=0, column=0, sticky=W, in_=self) self.vel = VelocitySelect.VELOCITIES[0] self.vel_selected = StringVar() vel_opts = ['%s (%s)' % (sp.name, sp.symbol) for sp in VelocitySelect.VELOCITIES] self.velopt = OptionMenu(self, self.vel_selected, *vel_opts) self.vel_selected.set('%s (%s)' % (self.vel.name, self.vel.symbol)) self.velopt.grid(row=0, column=1, sticky=W)
class HiddenNeuronNumber(Frame): def __init__(self, parent, layer_id): Frame.__init__(self, parent) self.parent = parent # Layer id is a number in range(MAX_NUMBER_OF_HIDDEN_LAYERS) self.layer_id = layer_id label_text = 'Neurons for layer {0}: '.format(layer_id + 1) self.label = Label(self, text = label_text) self.label.grid(row=0, column=0) number_options = range(1, MAX_NEURON_NUMBER_PER_HIDDEN_LAYER + 1) self.selected_number = \ IntVar(self, value = DEFAULT_NEURON_NUMBER_PER_HIDDEN_LAYER) self.option_menu = OptionMenu(self, self.selected_number, \ *number_options) self.option_menu.grid(row=0, column=1) self.disable() def get(self): return self.selected_number.get() def enable(self): self.label.config(state = 'normal') self.option_menu.config(state = 'normal') def disable(self): self.label.config(state = 'disabled') self.option_menu.config(state = 'disabled')