I have a ComboBox written in Python Tkinter that makes the horrible system alert sound when you click off of it without selecting something.
For instance, when you hit the dropdown and select your item, it works fine. But if you hit the drop-down and then decide to click off, it will lose focus as expected, but it makes an alert sound. Can this be disabled in some way so it can gracefully lose focus without complaining? I'm on OSX 10.9 btw
UPDATE - Minimally working code that produces the alert.
from Tkconstants import *
import ttk
import Tkinter
class PyPrecursor():
def __init__(self,root):
self.root = root
self.TabNotebook()
def TabNotebook(self):
self.main_notebook_frame = ttk.Notebook(self.root, name='main_notebook')
self.main_notebook_frame.enable_traversal()
self.OptionsF = ttk.Frame(self.main_notebook_frame, name='options')
self.length_options_frame = ttk.LabelFrame(
self.OptionsF, labelwidget=ttk.Label(font=('Arial', 15), text="Length Options:"))
self.hcdr3_length_label = ttk.Label(self.length_options_frame, text="HCDR3 Length")
self.HCDR3_Length = Tkinter.StringVar()
self.hcdr3_length_combo = ttk.Combobox(
self.length_options_frame, values=[i for i in xrange(16, 36)],
textvariable=self.HCDR3_Length)
self.hcdr3_length_combo.current(0)
self.length_options_frame.pack(side=TOP,fill=X,pady=5)
self.hcdr3_length_label.pack(side=LEFT)
self.hcdr3_length_combo.pack(side=LEFT,anchor=W)
self.main_notebook_frame.pack(side=TOP,expand=1,fill=BOTH,padx=10,pady=10)
self.main_notebook_frame.add(
self.OptionsF, text="Input Options", underline=0, padding=2)
self.main_notebook_frame.bind("<<NotebookTabChanged>>",self.update_)
def update_(self,event):
self.root.update()
def main():
root = Tkinter.Tk()
PyPrecursor(root)
root.mainloop()
root.update_idletasks()
if __name__ == '__main__':
main()
Setting focus to parent widget or to the root window removes focus from the target widget. Some widgets have takefocus option. Set takefocus to 0 to take your widget out of focus traversal (when user hits <Tab> key).
Focus is used to refer to the widget or window which is currently accepting input. Widgets can be used to restrict the use of mouse movement, grab focus, and keystrokes out of the bounds. However, if we want to focus a widget so that it gets activated for input, then we can use focus.
It focuses the widget and makes them active until the termination of the program.
The Tkinter Combobox is one of the UI widgets in the Tkinter library and it is used for to select the values in the drop-down list column also it is one of the combinations of Entry and drop-down widgets these drop-down entries are replaceable one and the user if suppose not select the value in the box it automatically ...
You might want to try this:
self.hcdr3_length_combo.bell(displayof=1)
Not sure if it should be 1 or 0 though... If it doesn't work, maybe a containing widget throws the sound. Might want to apply it to the parent widget as well. I'm not familiar with python 2.7 and it doesn't throw a sound when I use python3 with slight modifications.
Usually when you can't find an option for a specific widget, you can find something in the general widget options. Just search "tkinter widget options" and you'll get some place like: https://effbot.org/tkinterbook/widget.htm
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With