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.

Changing the text of Label won't update the terminal

See original GitHub issue

Changing the text of Label won’t update the terminal unless I move the mouse around in the console frame.

And I don’t find and update methods like label.Update() or label.Refresh().

OS: windows 10, terminal: CMD

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
qdwangcommented, Oct 30, 2021

Updating contents in Application.MainLoop.Invoke works for me. Thanks, problem is solved.

2reactions
tznindcommented, Oct 30, 2021

I have had a little look. The following minimum example works but if you remove Application.DoEvents() then it doesn’t work (requires the mouse to move before it will update). BDisp was it always like this or is this a regression/deliberate change?

static void Main(string[] args)
{
    Application.Init();

    var w = new Window();
    var lbl = new Label();
    w.Add(lbl);

    var t = new Task(()=>
    {
        while(true)
        {
            lbl.Text = DateTime.Now.ToString();
            lbl.SetNeedsDisplay();
            Application.DoEvents();
            Task.Delay(1000).Wait();
        }
    });

    t.Start();

    Application.Run(w);

    Application.Shutdown();


}

Update: I have checked the previous nuget version and behavior is consistent so it is not a regression. The following also works (and may be more correct). I think invoking on the main loop is the most thread safe way to update UIs in general especially for more complicated controls like TableView where you absolutely want to avoid changing the data in the view during redraw:

var t = new Task(()=>
{
    while(true)
    {
        Application.MainLoop.Invoke(()=>{
            lbl.Text = DateTime.Now.ToString();
            lbl.SetNeedsDisplay();
        });
        Task.Delay(1000).Wait();
    }
});

In fact you can even get rid of SetNeedsDisplay(); in the above example and it still works.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Update label text · Issue #1087 · gui-cs/Terminal.Gui
I cant seem to be able to change a labels text in any way, whether its changing the label.Text property or changing the...
Read more >
Issues Getting Button to Change Label Text - java
I've been having an issue where when I click a button to actually submit what is inside the text field, the label doesn't...
Read more >
Changing the Property Node label does not update the ...
If you change the control label, (or terminal label on the BD), the property node label updates accordingly. If you edit the property...
Read more >
How To Update Labels - Python Kivy GUI Tutorial #14
In this video I'll show you how to update labels in your Kivy app ... to enter text in a text box, click...
Read more >
Update a label text from subprocess - Python Forum
Hello, I try to code a graphical interface to run terminal command to show the result in a label. My problem is that...
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