_default is never updated after combo.clear() is called
See original GitHub issueI have 2 examples shown below which create a combo widget, clears out its contents and then rebuilds the combo’s contents. After doing so, calling select_default() fails because _default was never restored from the original value when the combo was originally inited.
Here is the warning output:
------------------------------------------------------------
*** GUIZERO WARNING ***
[Combo] object with options ['4', '5', '6']
Unable to select default option as doesnt exists in Combo
------------------------------------------------------------
Before pressing the button:
After pressing the button:
Example 1:
from guizero import App, Combo, PushButton
class ComboBug:
def __init__(self):
app = App(title="Hello world")
self.items1 = ['1', '2', '3']
self.items2 = ['4', '5', '6']
self.the_combo = Combo(app, options=self.items1)
self.the_button = PushButton(app, text='Push Me', command=self.switch_items)
app.display()
def switch_items(self):
self.the_combo.clear()
count = 0
for item in self.items2:
self.the_combo.insert(count, item)
count += 1
self.the_combo.select_default()
ComboBug()
Example 2:
from guizero import App, Combo, PushButton
class ComboBug2:
def __init__(self):
app = App(title="Hello world")
self.items1 = ['1', '2', '3']
self.items2 = ['4', '5', '6']
self.the_combo = Combo(app, options=self.items1)
self.the_button = PushButton(app, text='Push Me', command=self.switch_items)
app.display()
def switch_items(self):
self.the_combo.clear()
for item in self.items2:
self.the_combo.append(item)
self.the_combo.select_default()
ComboBug2()
Issue Analytics
- State:
- Created 5 years ago
- Comments:6
Top Results From Across the Web
Solved: Reset to default value in ComboBox
Solved: Hi, I have the following problem: I have a screen where a person has to select his own name from a list,...
Read more >javafx 2 - Combobox clearing value issue - Stack Overflow
The official "workaround" is to clear the value of the ComboBox after clearing selection. cb.getSelectionModel().clearSelection(); // Clear ...
Read more >Power Apps Combo Box DefaultSelectedItems - YouTube
It is no secret that the Combo box is a grumpy control. So in this video I break down how to make it...
Read more >Configure the form—ArcGIS Field Maps | Documentation
Default values are applied to a field whenever a feature is created and are helpful if there are common values that mobile workers...
Read more >ComboBox QML Type | Qt Quick Controls 6.4.1
The default value is false . This property was introduced in QtQuick.Controls 2.2 (Qt 5.9). See also validator.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ok, I would prefer to go with whatever you are most comfortable with. Thanks. I am not sure if want me to close this or not, just close it or let me know and I will do it. Thanks.
In scenario 2 (when a user selects a default at init), I am against changing the default because I am making choices about what the user wants.
I could change guizero so that it reverts the default to the first item in the list if the default is removed, but who is to say the user wont put it default option back in…
Its also consistent with scenario 1 - the user is “telling” guizero the default is the first option and that is never changed, the same with scenario 2, they tell guizero what the default is and then it never changes.