Python Tkinter.OptionMenu() Examples

The following are 11 code examples of Tkinter.OptionMenu(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module Tkinter , or try the search function .
Example #1
Source File: myNotebook.py    From EDMarketConnector with GNU General Public License v2.0 6 votes vote down vote up
def __init__(self, master, variable, default=None, *values, **kw):
        if platform == 'darwin':
            variable.set(default)
            bg = kw.pop('background', PAGEBG)
            tk.OptionMenu.__init__(self, master, variable, *values, **kw)
            self['background'] = bg
        elif platform == 'win32':
            # OptionMenu derives from Menubutton at the Python level, so uses Menubutton's style
            ttk.OptionMenu.__init__(self, master, variable, default, *values, style='nb.TMenubutton', **kw)
            self['menu'].configure(background = PAGEBG)
            # Workaround for https://bugs.python.org/issue25684
            for i in range(0, self['menu'].index('end')+1):
                self['menu'].entryconfig(i, variable=variable)
        else:
            ttk.OptionMenu.__init__(self, master, variable, default, *values, **kw)
            self['menu'].configure(background = ttk.Style().lookup('TMenu', 'background'))
            # Workaround for https://bugs.python.org/issue25684
            for i in range(0, self['menu'].index('end')+1):
                self['menu'].entryconfig(i, variable=variable) 
Example #2
Source File: test_widgets.py    From oss-ftp with MIT License 5 votes vote down vote up
def create(self, default='b', values=('a', 'b', 'c'), **kwargs):
        return tkinter.OptionMenu(self.root, None, default, *values, **kwargs) 
Example #3
Source File: strap_beam_gui.py    From Structural-Engineering with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def strap_design_frame_builder(self):
        self.strap_inputs_frame = tk.Frame(self.strap_design_frame)
        self.strap_inputs_frame.pack(side=tk.LEFT, anchor='nw')
        self.strap_calc_frame = tk.Frame(self.strap_design_frame)
        self.strap_calc_frame.pack(side=tk.RIGHT ,anchor='ne', fill=tk.BOTH, expand=1)


        tk.Label(self.strap_inputs_frame, text="B = ", font=self.helv).grid(row=0, column=0, sticky = tk.E)
        tk.Entry(self.strap_inputs_frame, textvariable=self.bs, width=10, validate="key", validatecommand=self.reset_status).grid(row=0, column=1)
        tk.Label(self.strap_inputs_frame, text="in", font=self.helv).grid(row=0, column=2)

        tk.Label(self.strap_inputs_frame, text="H = ", font=self.helv).grid(row=1, column=0, sticky = tk.E)
        tk.Entry(self.strap_inputs_frame, textvariable=self.hs, width=10, validate="key", validatecommand=self.reset_status).grid(row=1, column=1)
        tk.Label(self.strap_inputs_frame, text="in", font=self.helv).grid(row=1, column=2)

        self.strap_vbar_size = tk.StringVar()
        self.inputs.append(self.strap_vbar_size)
        self.strap_vbar_size.set('3')
        self.strap_vbar_size_label = tk.Label(self.strap_inputs_frame, text="Shear\nBar Size (#) : ", font=self.helv)
        self.strap_vbar_size_label.grid(row=2,column=0, pady=2)
        self.strap_vbar_size_menu = tk.OptionMenu(self.strap_inputs_frame, self.strap_vbar_size, '3', '4', '5', command=self.reset_status)
        self.strap_vbar_size_menu.config(font=self.helv)
        self.strap_vbar_size_menu.grid(row=2, column=1, padx= 2, sticky=tk.W)

        self.strap_bar_size = tk.StringVar()
        self.inputs.append(self.strap_bar_size)
        self.strap_bar_size.set('3')
        self.strap_bar_size_label = tk.Label(self.strap_inputs_frame, text="Flexure\nBar Size (#) : ", font=self.helv)
        self.strap_bar_size_label.grid(row=4,column=0, pady=2)
        self.strap_bar_size_menu = tk.OptionMenu(self.strap_inputs_frame, self.strap_bar_size, '3', '4', '5','6','7','8','9','10','11','14','18', command=self.reset_status)
        self.strap_bar_size_menu.config(font=self.helv)
        self.strap_bar_size_menu.grid(row=4, column=1, padx= 2, sticky=tk.W)

        self.strap_calc_txtbox = tk.Text(self.strap_calc_frame, height = 25, width = 70, bg= "grey90", font= self.helv_norm, wrap=tk.WORD)
        self.strap_calc_txtbox.grid(row=0, column=0, sticky='nsew')

        self.strap_scroll = tk.Scrollbar(self.strap_calc_frame, command=self.strap_calc_txtbox.yview)
        self.strap_scroll.grid(row=0, column=1, sticky='nsew')
        self.strap_calc_txtbox['yscrollcommand'] = self.strap_scroll.set 
Example #4
Source File: simple_beam_metric.py    From Structural-Engineering with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def build_loads_gui(self, *event):
        #Destroy all the individual tkinter gui elements for the current applied loads
        for load_gui in self.loads_gui:
            for gui_element in load_gui:
                gui_element.destroy()

        #Delete all the elements in the List containing the gui elements
        del self.loads_gui[:]
        del self.loads_scale[:]

        n = 0
        for loads in self.loads_gui_select_var:
            load_types = ['Point','Moment','UDL','TRAP']
            load_locals = ['Left','Center','Right']

            if loads[6].get() == 'Moment':
                self.loads_scale.append(float(loads[1].get())/2.0)
            else:
                self.loads_scale.append(float(loads[1].get()))
            self.loads_scale.append(float(loads[2].get()))

            self.loads_gui.append([
                tk.Checkbutton(self.loads_frame, variable=loads[0], command = self.build_loads),
                tk.Entry(self.loads_frame, textvariable=loads[1], width=15),
                tk.Entry(self.loads_frame, textvariable=loads[2], width=15),
                tk.Entry(self.loads_frame, textvariable=loads[3], width=15),
                tk.Entry(self.loads_frame, textvariable=loads[4], width=15),
                tk.OptionMenu(self.loads_frame, loads[5], *load_locals),
                tk.OptionMenu(self.loads_frame, loads[6], *load_types)])

            self.loads_gui[n][0].grid(row=n+1, column=1)
            self.loads_gui[n][1].grid(row=n+1, column=2, padx = 4)
            self.loads_gui[n][2].grid(row=n+1, column=3, padx = 4)
            self.loads_gui[n][3].grid(row=n+1, column=4, padx = 4)
            self.loads_gui[n][4].grid(row=n+1, column=5, padx = 4)
            self.loads_gui[n][5].grid(row=n+1, column=6)
            self.loads_gui[n][6].grid(row=n+1, column=7)
            n+=1 
Example #5
Source File: simple_beam.py    From Structural-Engineering with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def build_loads_gui(self, *event):
        #Destroy all the individual tkinter gui elements for the current applied loads
        for load_gui in self.loads_gui:
            for gui_element in load_gui:
                gui_element.destroy()

        #Delete all the elements in the List containing the gui elements
        del self.loads_gui[:]
        del self.loads_scale[:]

        n = 0
        for loads in self.loads_gui_select_var:
            load_types = ['Point','Moment','UDL','TRAP']
            load_locals = ['Left','Center','Right']

            if loads[6].get() == 'Moment':
                self.loads_scale.append(float(loads[1].get())/2.0)
            else:
                self.loads_scale.append(float(loads[1].get()))
            self.loads_scale.append(float(loads[2].get()))

            self.loads_gui.append([
                tk.Checkbutton(self.loads_frame, variable=loads[0], command = self.build_loads),
                tk.Entry(self.loads_frame, textvariable=loads[1], width=15),
                tk.Entry(self.loads_frame, textvariable=loads[2], width=15),
                tk.Entry(self.loads_frame, textvariable=loads[3], width=15),
                tk.Entry(self.loads_frame, textvariable=loads[4], width=15),
                tk.OptionMenu(self.loads_frame, loads[5], *load_locals),
                tk.OptionMenu(self.loads_frame, loads[6], *load_types)])

            self.loads_gui[n][0].grid(row=n+1, column=1)
            self.loads_gui[n][1].grid(row=n+1, column=2, padx = 4)
            self.loads_gui[n][2].grid(row=n+1, column=3, padx = 4)
            self.loads_gui[n][3].grid(row=n+1, column=4, padx = 4)
            self.loads_gui[n][4].grid(row=n+1, column=5, padx = 4)
            self.loads_gui[n][5].grid(row=n+1, column=6)
            self.loads_gui[n][6].grid(row=n+1, column=7)
            n+=1 
Example #6
Source File: aisc_steel_shapes.py    From Structural-Engineering with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def shape_click(self, *event):
        shape = self.shape_menu.get(self.shape_menu.curselection())
        shape_index = self.shape_types.index(self.shape_type.get())
        section_props = self.shape_sets[shape_index].get(shape)

        if section_props[0] == 'F':
            self.data_frame.configure(text="Section Properties - AISC 14th Edition:  --  Selected Shape: "+shape)
        else:
            note = self.shape_special_note[shape_index]
            self.data_frame.configure(text="Section Properties - AISC 14th Edition:  --  Selected Shape: "+shape+" -- Note: "+note)
        for labels in self.properties_labels:
            labels.configure( text=' ')

        props_counter = 0
        props_list = []
        for i in range(1,len(self.values_list)):
            if section_props[i] == '-':
               pass
            else:
                if self.values_units[i] == '':
                    string = '{0}{1}:\n{2}'.format(self.values_list[i],self.values_units[i],section_props[i])
                else:
                    string = '{0}({1}):\n{2}'.format(self.values_list[i],self.values_units[i],section_props[i])
                    props_list.append(self.values_list[i])
                    
                self.properties_labels[props_counter].configure( text=string)                
                props_counter+=1

        self.value_def_menu.destroy()
        self.value_def_menu = tk.OptionMenu(self.value_def_frame, self.value_def, *props_list, command=self.value_definitions)
        helv = tkFont.Font(family='Helvetica',size=self.f_size, weight='bold')
        self.value_def_menu.config(font=helv)
        self.value_def_menu.grid(row=0, column=0, padx=1, pady=1)
        self.value_def.set(props_list[0])
        self.value_definitions() 
Example #7
Source File: aisc_steel_shapes_historic.py    From Structural-Engineering with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def edition_change(self, *event):
        self.shape_type_menu.destroy()
        edition = self.edition_type.get()
        edition_index = self.edition.index(edition)
        self.shape_type_menu = tk.OptionMenu(self.menu_frame, self.shape_type, *self.shape_sets[edition_index], command=self.shape_change)
        helv = tkFont.Font(family='Helvetica',size=self.f_size, weight='bold')
        self.shape_type_menu.config(font=helv)
        self.shape_type_menu.pack(side=tk.TOP, fill=tk.X, expand=True)
        self.shape_type.set(self.shape_sets[edition_index][0]) 
Example #8
Source File: Tkinter_Widget_Examples.py    From MacAdmins-2016-Craft-GUIs-with-Python-and-Tkinter with MIT License 5 votes vote down vote up
def __init__(self, master):
        tk.Frame.__init__(self, master)
        self.pack(padx=20, pady=20)

        self.master = master

        options = ['white', 'red', 'green', 'blue']

        self.selection = tk.StringVar()
        self.selection.set('White')

        tk.Label(self, text="This is an optionmenu").pack()

        tk.OptionMenu(self, self.selection, *[x.capitalize() for x in options], command=self.set_color).pack() 
Example #9
Source File: pcwg_tool_reborn.py    From PCWG with MIT License 5 votes vote down vote up
def addOption(self, master, title, options, value):

            label = tk.Label(master, text=title)
            label.grid(row=self.row, sticky=tk.W, column=self.labelColumn)

            variable = tk.StringVar(master, value)

            option = apply(tk.OptionMenu, (master, variable) + tuple(options))
            option.grid(row=self.row, column=self.inputColumn, sticky=tk.W)

            self.row += 1

            return variable 
Example #10
Source File: base_dialog.py    From PCWG with MIT License 5 votes vote down vote up
def addOption(self, master, title, options, value):

        label = tk.Label(master, text=title)
        label.grid(row=self.row, sticky=tk.W, column=self.labelColumn)

        variable = tk.StringVar(master, value)

        option = apply(tk.OptionMenu, (master, variable) + tuple(options))
        option.grid(row=self.row, column=self.inputColumn, sticky=tk.W)

        self.row += 1

        return variable 
Example #11
Source File: test_widgets.py    From PokemonGo-DesktopMap with MIT License 5 votes vote down vote up
def create(self, default='b', values=('a', 'b', 'c'), **kwargs):
        return tkinter.OptionMenu(self.root, None, default, *values, **kwargs)