Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear text field part of ttk.Combobox?

I have a delete function that is supposed to remove the selected item in the Combobox and its associated dictionary value. Then it is supposed to clear the textbox that displays that dictionary value and I would like it to also clear just the text file of the combo box. Is there a way to do that?

def DeleteEntry():
    if not ComboBox.get() == "" and ComboBox.get() in FriendMap:
        del FriendMap[ComboBox.get()]
        FriendListKeys = FriendMap.keys()
        FriendListKeys.sort()
        ComboBox['values']=FriendListKeys
        FriendListBox.delete(1.0,2.0)

That is what I have thus far but I would like the next line to delete the text field in the Combobox.

like image 642
Marek Avatar asked Feb 05 '16 20:02

Marek


People also ask

How do you clear a text field in Python?

Type something inside the textbox, and then, click the “Delete” button. It will erase the content inside the textbox.

How do you delete text in text widget?

Tkinter Text Widget is used to add the text writer in an application. It has many attributes and properties which are used to extend the functionality of a text editor. In order to delete the input content, we can use the delete("start", "end") method.

How do I use TTK combobox?

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 ...

What is Textvariable in tkinter combobox?

textvariable. A variable linked to the current value of the combobox; when the variable is changed, the current value of the combobox will be updated, while when the user changes the combobox, the variable will be updated. values.


2 Answers

You can clear the selected value of a Combobox by setting its value to an empty string:

ComboBox.set('')
like image 152
Uyghur Lives Matter Avatar answered Sep 30 '22 13:09

Uyghur Lives Matter


Set the StringVar of the combobox to empty string instead of the Widget itself.

def clear():
    var.set('')
var = tk.StringVar()
values = ['one', 'two', 'three']
cb = tk.ttk.Combobox(root, state = 'readonly', textvariable = var, values = values)
cb.pack()
like image 36
Angad Kulkarni Avatar answered Sep 30 '22 13:09

Angad Kulkarni