'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.
Solution 1:[1]
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()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Angad Kulkarni |
