def __init__(self, master, dictionary, *args, **kwargs): Combobox.__init__(self, master, values=sorted(list(dictionary.keys())), *args, **kwargs) self.dictionary = dictionary
def __init__(self, frame, options, stringvar=None, width=20, height=21): self.text_font = ('Microsoft Sans Serif', '10') combostyle = Style() combostyle.theme_create('combostyle', parent='alt', settings={ "TCombobox": { "configure": { "selectbackground": "#F7A5D2", "fieldbackground": "#F7A5D2", "background": "#C0C0C0", "selectforeground": "black", "bordercolor": "#C0C0C0" } } }) combostyle.theme_use('combostyle') Combobox.__init__(self, frame, values=options, textvariable=stringvar, width=width, height=height, state="readonly", font=self.text_font) frame.root.option_add('*TCombobox*Listbox.font', self.text_font) self.bind("<<ComboboxSelected>>", self.do)
def __init__(self, boss, repertoire): contenu = listdir('Objets/' + repertoire) self.listObjets = {} listStrObjets = [] for nom in contenu: self.listObjets[nom[:-4]] = Objet(repertoire, nom) #Le [:-4] permet de supprimer le ".txt" listStrObjets.append(nom[:-4]) Combobox.__init__(self, boss, values = listStrObjets, state='readonly')
def __init__(self, boss, repertoire): contenu = listdir('Objets/' + repertoire) self.listObjets = {} listStrObjets = [] for nom in contenu: self.listObjets[nom[:-4]] = Objet( repertoire, nom) #Le [:-4] permet de supprimer le ".txt" listStrObjets.append(nom[:-4]) Combobox.__init__(self, boss, values=listStrObjets, state='readonly')
def __init__(self, parent, option, **kargs): values = [m.__name__.replace('Mode', '') for m in option] self.state = StringVar() self.option = dict(zip(values, option)) Combobox.__init__(self, parent, values=values, textvariable=self.state, **kargs) self.mode = self.option[values[0]](keyword_frame) self.mode.pack() self.current(0) self.bind("<<ComboboxSelected>>", self.select)
def __init__(self, parent): selectText = Label(parent, text="Sélectionner une liste des composants", font=("Calibri", 11), background="white") selectText.pack(side="top", pady=25) self.dataBaseSelected = StringVar() Combobox.__init__(self, parent, width=25, state="readonly", textvariable=self.dataBaseSelected) self.pack(side="top", pady=25)
def __init__(self, master, x, y, value="", values=(), width=None, objectId=None, columnspan=None, selectindex=None, comboboxselected=None, state=None, padx=None, attr=None): _Combobox.__init__(self, master=master) self.attr = attr self.valueVar = StringVar() self.valueVar.trace('w', self.valueChanged) self.config(textvariable=self.valueVar, background="#ff8ff8ff8", foreground="#000000000", # justify='center' width=width, state=state ) self["values"] = values if isinstance(master.master.master, scrolledHeaderedFrame): x = x * 2 y = y * 2 if columnspan: columnspan = columnspan * 2 - 1 if columnspan and columnspan > 1: self.grid(column=x, row=y, sticky=(E,W), columnspan=columnspan, padx=padx) else: self.grid(column=x, row=y, sticky=(E,W), padx=padx) if selectindex is not None: self.valueVar.set(values[selectindex]) elif value: self.valueVar.set(value) elif attr: try: options = master.master.options if attr in options: self.valueVar.set( options[attr] or "" ) except AttributeError: pass self.objectId = objectId # copy bindings try: contextMenuBinding = master.bind(master.contextMenuClick) if contextMenuBinding: self.bind(master.contextMenuClick, contextMenuBinding) except AttributeError: pass if comboboxselected: self.bind("<<ComboboxSelected>>", comboboxselected) self.isChanged = False
def __init__(self, labels=None): labels = input('Enter field names: ').split() Combobox.__init__(self, labels)
def __init__(self, master=None, allow_other_values=False, additional_validation=None, **kwargs): """ Create a AutoCompleteCombobox, i.e. a Combobox with autocompletion. Keyword arguments: - the same arguments as a Comboxbox but the validatecommand is not taken into account - allow_other_values (boolean): whether the user is allowed to enter values not in the list - additional_validation (function): if 'allow_other_values' is True and the inserted text is not in the list, apply 'additional_validation' to what will be the content of the entry after the change. Therefore 'additional_validation' must be a function taking as argument a string (the text in the entry if the change is allowed) and returning a boolean depending on whether the change should be allowed. """ Combobox.__init__(self, master, **kwargs) self._allow_other_values = allow_other_values if additional_validation is None: self._additional_validation = lambda txt: True else: self._additional_validation = additional_validation self._validate = self.register(self.validate) self.configure(validate='key', validatecommand=(self._validate, "%d", "%S", "%i", "%s", "%P")) # navigate on keypress in the dropdown self.tk.eval(""" proc ComboListKeyPressed {w key} { if {[string length $key] > 1 && [string tolower $key] != $key} { return } set cb [winfo parent [winfo toplevel $w]] set text [string map [list {[} {\[} {]} {\]}] $key] if {[string equal $text ""]} { return } set values [$cb cget -values] set x [lsearch -glob -nocase $values $text*] if {$x < 0} { return } set current [$w curselection] if {$current == $x && [string match -nocase $text* [lindex $values [expr {$x+1}]]]} { incr x } $w selection clear 0 end $w selection set $x $w activate $x $w see $x } set popdown [ttk::combobox::PopdownWindow %s] bind $popdown.f.l <KeyPress> [list ComboListKeyPressed %%W %%K] """ % (self))
def __init__(self, master, **options): Combobox.__init__(self, master, **options) self.queue = Queue() self.update_me()