Python ttk.Combobox() Examples

The following are 15 code examples for showing how to use ttk.Combobox(). These examples are extracted from open source projects. 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 check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module ttk , or try the search function .

Example 1
Project: SEM   Author: YoannDupont   File: components.py    License: MIT License 9 votes vote down vote up
def __init__(self, root, resource_dir):
        ttk.Frame.__init__(self, root)
        
        self.master_selector = None
        self.resource_dir = resource_dir
        self.items = os.listdir(os.path.join(self.resource_dir, "master"))
        
        self.cur_lang = tkinter.StringVar()
        self.select_lang_label = ttk.Label(root, text=u"select language:")
        self.langs = ttk.Combobox(root, textvariable=self.cur_lang)
        
        self.langs["values"] = self.items

        self.langs.current(0)
        for i, item in enumerate(self.items):
            if item == "fr":
                self.langs.current(i)
        
        self.langs.bind("<<ComboboxSelected>>", self.select_lang) 
Example 2
Project: SEM   Author: YoannDupont   File: components.py    License: MIT License 5 votes vote down vote up
def __init__(self, root):
        ttk.Frame.__init__(self, root)
        
        self.root = root
        self.label = ttk.Label(self.root, text=u"select output format:")
        
        self.export_formats = ["default"] + [exporter[:-3] for exporter in os.listdir(os.path.join(sem.SEM_HOME, "exporters")) if (exporter.endswith(".py") and not exporter.startswith("_") and not exporter == "exporter.py")]
        self.export_combobox = ttk.Combobox(self.root)
        self.export_combobox["values"] = self.export_formats
        self.export_combobox.current(0) 
Example 3
Project: lackey   Author: glitchassassin   File: SikuliGui.py    License: MIT License 5 votes vote down vote up
def __init__(self, parent, msg, title, options, default, text_variable):
        tk.Frame.__init__(self, parent)
        self.parent = parent
        self.parent.protocol("WM_DELETE_WINDOW", self.cancel_function)
        self.parent.bind('<Return>', self.ok_function)
        self.parent.title(title)
        self.input_text = text_variable
        self.input_text.set(default)
        if Settings.PopupLocation:
            self.parent.geometry("+{}+{}".format(
                Settings.PopupLocation.x,
                Settings.PopupLocation.y))
        self.msg = tk.Message(self.parent, text=msg)
        self.msg.grid(row=0, sticky="NSEW", padx=10, pady=10)
        self.input_list = ttk.Combobox(
            self.parent,
            textvariable=self.input_text,
            state="readonly",
            values=options)
        #self.input_list.activate(options.index(default))
        self.input_list.grid(row=1, sticky="EW", padx=10)
        self.button_frame = tk.Frame(self.parent)
        self.button_frame.grid(row=2, sticky="E")
        self.cancel = tk.Button(
            self.button_frame,
            text="Cancel",
            command=self.cancel_function,
            width=10)
        self.cancel.grid(row=0, column=0, padx=10, pady=10)
        self.ok_button = tk.Button(
            self.button_frame,
            text="Ok",
            command=self.ok_function,
            width=10)
        self.ok_button.grid(row=0, column=1, padx=10, pady=10)
        self.input_list.focus_set() 
Example 4
Project: BinderFilter   Author: dxwu   File: test_widgets.py    License: MIT License 5 votes vote down vote up
def setUp(self):
        support.root_deiconify()
        self.combo = ttk.Combobox() 
Example 5
Project: oss-ftp   Author: aliyun   File: test_widgets.py    License: MIT License 5 votes vote down vote up
def create(self, **kwargs):
        return ttk.Combobox(self.root, **kwargs) 
Example 6
Project: py-kms   Author: SystemRage   File: pykms_GuiBase.py    License: The Unlicense 5 votes vote down vote up
def clt_eject(self):
                while self.clientthread.is_alive():
                        sleep(0.1)

                widgets = self.storewidgets_clt + [self.runbtnclt]
                if not self.onlyclt:
                        widgets += [self.runbtnsrv]

                for widget in widgets:
                        if isinstance(widget, ttk.Combobox):
                                widget.configure(state = 'readonly')
                        else:
                                widget.configure(state = 'normal')
                                if isinstance(widget, ListboxOfRadiobuttons):
                                        widget.change() 
Example 7
def __init__(self, master):
        ttk.Frame.__init__(self, master)
        self.pack()

        options = ['Minneapolis', 'Eau Claire', 'Cupertino', 'New York', 'Amsterdam', 'Sydney', 'Hong Kong']

        ttk.Label(self, text="This is a combobox").pack(pady=10)

        self.combo = ttk.Combobox(self, values=options, state='readonly')
        self.combo.current(0)
        self.combo.pack(padx=15)

        ttk.Button(self, text='OK', command=self.ok).pack(side='right', padx=15, pady=10) 
Example 8
Project: Video-Downloader   Author: EvilCult   File: guiClass.py    License: GNU General Public License v2.0 5 votes vote down vote up
def __selector (self, position) :
		self.selectorVal = Tkinter.StringVar()
		self.selectorVal.set("HD")

		videoType = ['HD', '超清', '高清']

		s = ttk.Combobox(position, width = 5, textvariable = self.selectorVal, state='readonly', values = videoType)

		return s 
Example 9
Project: PokemonGo-DesktopMap   Author: mchristopher   File: test_widgets.py    License: MIT License 5 votes vote down vote up
def create(self, **kwargs):
        return ttk.Combobox(self.root, **kwargs) 
Example 10
Project: SEM   Author: YoannDupont   File: annotation_gui.py    License: MIT License 4 votes vote down vote up
def load_tagset(self, filename):
        if self.doc and self.doc_is_modified:
            update_annotations(self.doc, self.annotation_name, self.current_annotations.annotations)
        
        tagset_name = os.path.splitext(os.path.basename(filename))[0]
        tagset = []
        with codecs.open(filename, "rU", "utf-8") as I:
            for line in I:
                tagset.append(line.strip())
        tagset = [tag.split(u"#",1)[0] for tag in tagset]
        tagset = [tag for tag in tagset if tag != u""]
        
        self.spare_colors = self.SPARE_COLORS_DEFAULT[:]
        self.annotation_name = tagset_name
        self.tagset = set(tagset)
        
        for combo in self.type_combos:
            combo.destroy()
        self.type_combos = []
        for add_type_lbl in self.add_type_lbls:
            add_type_lbl.destroy()
        self.add_type_lbls = [ttk.Label(self.toolbar, text="add type:")]
        self.add_type_lbls[0].pack(side="left")
        
        for child in self.tree.get_children():
            self.tree.delete(child)
        self.tree_ids[self.annotation_name] = self.tree.insert("", len(self.tree_ids)+1, text=self.annotation_name)
        self.tree_ids["history"] = self.tree.insert("", len(self.tree_ids)+1, text="history")
        self.annot2treeitems[self.annotation_name] = {}
        
        self.type_combos.append(ttk.Combobox(self.toolbar))
        self.type_combos[0]["values"] = [self.SELECT_TYPE]
        self.type_combos[0].bind("<<ComboboxSelected>>", self.add_annotation)
        self.type_combos[0].pack(side="left")
        
        self.adder = Adder2.from_tagset(tagset)
        for depth in range(self.adder.max_depth()):
            ## label
            self.add_type_lbls.append(ttk.Label(self.toolbar, text="add {0}type:".format("sub"*(depth))))
            self.add_type_lbls[depth].pack(side="left")
            # combobox
            self.type_combos.append(ttk.Combobox(self.toolbar))
            self.type_combos[depth]["values"] = [self.SELECT_TYPE]
            self.type_combos[depth].bind("<<ComboboxSelected>>", self.add_annotation)
            self.type_combos[depth].pack(side="left")
            for tag in sorted(set([t[depth] for t in self.adder.levels if len(t) > depth])):
                if len(self.type_combos) > 0:
                    self.type_combos[depth]["values"] = list(self.type_combos[depth]["values"]) + [tag]
                if depth == 0:
                    if len(self.spare_colors) > 0:
                        self.color = self.spare_colors.pop()
                    else:
                        self.color = random_color()
                    self.text.tag_configure(tag, **self.color)
        self.update_level()
        self.doc = None
        self.load_document() 
Example 11
Project: BinderFilter   Author: dxwu   File: test_widgets.py    License: MIT License 4 votes vote down vote up
def test_values(self):
        def check_get_current(getval, currval):
            self.assertEqual(self.combo.get(), getval)
            self.assertEqual(self.combo.current(), currval)

        check_get_current('', -1)

        self.combo['values'] = ['a', 1, 'c']

        self.combo.set('c')
        check_get_current('c', 2)

        self.combo.current(0)
        check_get_current('a', 0)

        self.combo.set('d')
        check_get_current('d', -1)

        # testing values with empty string
        self.combo.set('')
        self.combo['values'] = (1, 2, '', 3)
        check_get_current('', 2)

        # testing values with empty string set through configure
        self.combo.configure(values=[1, '', 2])
        self.assertEqual(self.combo['values'], ('1', '', '2'))

        # testing values with spaces
        self.combo['values'] = ['a b', 'a\tb', 'a\nb']
        self.assertEqual(self.combo['values'], ('a b', 'a\tb', 'a\nb'))

        # testing values with special characters
        self.combo['values'] = [r'a\tb', '"a"', '} {']
        self.assertEqual(self.combo['values'], (r'a\tb', '"a"', '} {'))

        # out of range
        self.assertRaises(Tkinter.TclError, self.combo.current,
            len(self.combo['values']))
        # it expects an integer (or something that can be converted to int)
        self.assertRaises(Tkinter.TclError, self.combo.current, '')

        # testing creating combobox with empty string in values
        combo2 = ttk.Combobox(values=[1, 2, ''])
        self.assertEqual(combo2['values'], ('1', '2', ''))
        combo2.destroy() 
Example 12
Project: oss-ftp   Author: aliyun   File: test_widgets.py    License: MIT License 4 votes vote down vote up
def test_values(self):
        def check_get_current(getval, currval):
            self.assertEqual(self.combo.get(), getval)
            self.assertEqual(self.combo.current(), currval)

        self.assertEqual(self.combo['values'],
                         () if tcl_version < (8, 5) else '')
        check_get_current('', -1)

        self.checkParam(self.combo, 'values', 'mon tue wed thur',
                        expected=('mon', 'tue', 'wed', 'thur'))
        self.checkParam(self.combo, 'values', ('mon', 'tue', 'wed', 'thur'))
        self.checkParam(self.combo, 'values', (42, 3.14, '', 'any string'))
        self.checkParam(self.combo, 'values', () if tcl_version < (8, 5) else '')

        self.combo['values'] = ['a', 1, 'c']

        self.combo.set('c')
        check_get_current('c', 2)

        self.combo.current(0)
        check_get_current('a', 0)

        self.combo.set('d')
        check_get_current('d', -1)

        # testing values with empty string
        self.combo.set('')
        self.combo['values'] = (1, 2, '', 3)
        check_get_current('', 2)

        # testing values with empty string set through configure
        self.combo.configure(values=[1, '', 2])
        self.assertEqual(self.combo['values'],
                         ('1', '', '2') if self.wantobjects else
                         '1 {} 2')

        # testing values with spaces
        self.combo['values'] = ['a b', 'a\tb', 'a\nb']
        self.assertEqual(self.combo['values'],
                         ('a b', 'a\tb', 'a\nb') if self.wantobjects else
                         '{a b} {a\tb} {a\nb}')

        # testing values with special characters
        self.combo['values'] = [r'a\tb', '"a"', '} {']
        self.assertEqual(self.combo['values'],
                         (r'a\tb', '"a"', '} {') if self.wantobjects else
                         r'a\\tb {"a"} \}\ \{')

        # out of range
        self.assertRaises(tkinter.TclError, self.combo.current,
            len(self.combo['values']))
        # it expects an integer (or something that can be converted to int)
        self.assertRaises(tkinter.TclError, self.combo.current, '')

        # testing creating combobox with empty string in values
        combo2 = ttk.Combobox(self.root, values=[1, 2, ''])
        self.assertEqual(combo2['values'],
                         ('1', '2', '') if self.wantobjects else '1 2 {}')
        combo2.destroy() 
Example 13
Project: ms_deisotope   Author: mobiusklein   File: view.py    License: Apache License 2.0 4 votes vote down vote up
def configure_display_row(self):
        self.display_row = ttk.Frame(self)
        self.display_row.grid(row=1, column=0, sticky=tk.W + tk.S + tk.E)
        self.cursor_label = ttk.Label(self.display_row, text=" " * 20)
        self.cursor_label.grid(row=0, padx=(10, 10))

        def update_label(*args, **kwargs):
            self.cursor_label['text'] = self.canvas_cursor.binding.get()

        self.canvas_cursor.binding.trace('w', update_label)

        self.ms1_averagine_combobox = ttk.Combobox(self.display_row, values=[
            "peptide",
            "glycan",
            "glycopeptide",
            "heparan sulfate",
        ], width=15)
        self.ms1_averagine_combobox.set("glycopeptide")
        self.ms1_averagine_combobox_label = ttk.Label(self.display_row, text="MS1 Averagine:")
        self.ms1_averagine_combobox_label.grid(row=0, column=1, padx=(10, 0))
        self.ms1_averagine_combobox.grid(row=0, column=2, padx=(1, 10))

        self.msn_averagine_combobox = ttk.Combobox(self.display_row, values=[
            "peptide",
            "glycan",
            "glycopeptide",
            "heparan sulfate",
        ], width=15)
        self.msn_averagine_combobox.set("peptide")
        self.msn_averagine_combobox_label = ttk.Label(self.display_row, text="MSn Averagine:")
        self.msn_averagine_combobox_label.grid(row=0, column=3, padx=(10, 0))
        self.msn_averagine_combobox.grid(row=0, column=4, padx=(1, 10))

        self.ms1_scan_averaging_label = ttk.Label(
            self.display_row, text="MS1 Signal Averaging:")
        self.ms1_scan_averaging_label.grid(row=0, column=5, padx=(10, 0))
        self.ms1_scan_averaging_var = tk.IntVar(self, value=2)
        self.ms1_scan_averaging = ttk.Entry(self.display_row, width=3)
        self.ms1_scan_averaging['textvariable'] = self.ms1_scan_averaging_var
        self.ms1_scan_averaging.grid(row=0, column=6, padx=(1, 3))

        self.min_charge_state_var = tk.IntVar(self, value=1)
        self.max_charge_state_var = tk.IntVar(self, value=12)
        self.min_charge_state_label = ttk.Label(
            self.display_row, text="Min Charge:")
        self.min_charge_state_label.grid(row=0, column=7, padx=(5, 0))
        self.min_charge_state = ttk.Entry(self.display_row, width=3)
        self.min_charge_state['textvariable'] = self.min_charge_state_var
        self.min_charge_state.grid(row=0, column=8, padx=(1, 3))

        self.max_charge_state_label = ttk.Label(
            self.display_row, text="Max Charge:")
        self.max_charge_state_label.grid(row=0, column=9, padx=(5, 0))
        self.max_charge_state = ttk.Entry(self.display_row, width=3)
        self.max_charge_state['textvariable'] = self.max_charge_state_var
        self.max_charge_state.grid(row=0, column=10, padx=(1, 3)) 
Example 14
Project: cheetah-gui   Author: shmilylty   File: cheetah_dictionary.py    License: GNU General Public License v3.0 4 votes vote down vote up
def __init__(self, top=None):
        """This class configures and populates the toplevel window.
           top is the toplevel containing window."""
        _bgcolor = '#d9d9d9'  # X11 color: 'gray85'
        _fgcolor = '#000000'  # X11 color: 'black'
        _compcolor = '#d9d9d9'  # X11 color: 'gray85'
        _ana2color = '#d9d9d9'  # X11 color: 'gray85'
        self.style = ttk.Style()
        if sys.platform == "win32":
            self.style.theme_use('winnative')
        self.style.configure('.', background=_bgcolor)
        self.style.configure('.', foreground=_fgcolor)
        self.style.configure('.', font="TkDefaultFont")
        self.style.map('.', background=[('selected', _compcolor), ('active', _ana2color)])

        top.geometry("398x150+490+300")
        top.title("Cheetah Dictionary Setting")
        top.configure(background="#d9d9d9")
        top.configure(highlightbackground="#d9d9d9")
        top.configure(highlightcolor="black")
        top.resizable(0, 0)

        self.Label1 = Label(top)
        self.Label1.place(relx=0.05, rely=0.27, height=27, width=36)
        self.Label1.configure(background="#d9d9d9")
        self.Label1.configure(foreground="#000000")
        self.Label1.configure(text='''Path :''')

        self.Button1 = Button(top)
        self.Button1.place(relx=0.89, rely=0.27, height=24, width=24)
        self.Button1.configure(takefocus="")
        self.Button1.configure(text='''...''')
        self.Button1.configure(command=cheetah_dictionary_support.set_pwd_file)

        self.TButton2 = ttk.Button(top)
        self.TButton2.place(relx=0.21, rely=0.6, height=27, width=98)
        self.TButton2.configure(takefocus="")
        self.TButton2.configure(text='''Dereplicat''')
        self.TButton2.configure(command=cheetah_dictionary_support.dereplicat_pwd_file)

        self.TButton3 = ttk.Button(top)
        self.TButton3.place(relx=0.54, rely=0.6, height=27, width=98)
        self.TButton3.configure(takefocus="")
        self.TButton3.configure(text='''OK''')
        self.TButton3.configure(command=cheetah_dictionary_support.exit_dict_setting)

        self.TCombobox1 = ttk.Combobox(top)
        self.TCombobox1.place(relx=0.15, rely=0.27, relheight=0.18, relwidth=0.74)
        self.TCombobox1.configure(values=cheetah_dictionary_support.dict_list)
        self.TCombobox1.configure(textvariable=cheetah_dictionary_support.dict_path_var)
        self.TCombobox1.configure(takefocus="")
        # self.TCombobox1.set(cheetah_dictionary_support.dict_path) 
Example 15
Project: PokemonGo-DesktopMap   Author: mchristopher   File: test_widgets.py    License: MIT License 4 votes vote down vote up
def test_values(self):
        def check_get_current(getval, currval):
            self.assertEqual(self.combo.get(), getval)
            self.assertEqual(self.combo.current(), currval)

        self.assertEqual(self.combo['values'],
                         () if tcl_version < (8, 5) else '')
        check_get_current('', -1)

        self.checkParam(self.combo, 'values', 'mon tue wed thur',
                        expected=('mon', 'tue', 'wed', 'thur'))
        self.checkParam(self.combo, 'values', ('mon', 'tue', 'wed', 'thur'))
        self.checkParam(self.combo, 'values', (42, 3.14, '', 'any string'))
        self.checkParam(self.combo, 'values', () if tcl_version < (8, 5) else '')

        self.combo['values'] = ['a', 1, 'c']

        self.combo.set('c')
        check_get_current('c', 2)

        self.combo.current(0)
        check_get_current('a', 0)

        self.combo.set('d')
        check_get_current('d', -1)

        # testing values with empty string
        self.combo.set('')
        self.combo['values'] = (1, 2, '', 3)
        check_get_current('', 2)

        # testing values with empty string set through configure
        self.combo.configure(values=[1, '', 2])
        self.assertEqual(self.combo['values'],
                         ('1', '', '2') if self.wantobjects else
                         '1 {} 2')

        # testing values with spaces
        self.combo['values'] = ['a b', 'a\tb', 'a\nb']
        self.assertEqual(self.combo['values'],
                         ('a b', 'a\tb', 'a\nb') if self.wantobjects else
                         '{a b} {a\tb} {a\nb}')

        # testing values with special characters
        self.combo['values'] = [r'a\tb', '"a"', '} {']
        self.assertEqual(self.combo['values'],
                         (r'a\tb', '"a"', '} {') if self.wantobjects else
                         r'a\\tb {"a"} \}\ \{')

        # out of range
        self.assertRaises(tkinter.TclError, self.combo.current,
            len(self.combo['values']))
        # it expects an integer (or something that can be converted to int)
        self.assertRaises(tkinter.TclError, self.combo.current, '')

        # testing creating combobox with empty string in values
        combo2 = ttk.Combobox(self.root, values=[1, 2, ''])
        self.assertEqual(combo2['values'],
                         ('1', '2', '') if self.wantobjects else '1 2 {}')
        combo2.destroy()