question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

_default is never updated after combo.clear() is called

See original GitHub issue

I 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: screenshot from 2018-07-15 16-11-23

After pressing the button: screenshot from 2018-07-15 16-11-58

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:closed
  • Created 5 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
MrYsLabcommented, Jul 16, 2018

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.

0reactions
martinohanloncommented, Jul 16, 2018

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.

Read more comments on GitHub >

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

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found