[GH-ISSUE #916] NewButton.SetBorder(true) & NewButton.SetBackgroundColor(tcell.Color*[ANY]) results in a Button Text Wipeout Issue!? #668

Closed
opened 2026-03-04 01:06:54 +03:00 by kerem · 2 comments
Owner

Originally created by @WhipMeHarder on GitHub (Nov 16, 2023).
Original GitHub issue: https://github.com/rivo/tview/issues/916

Hello Any/All,
I have written some very simple code to test adding buttons to a tview Grid. However, when I try to change or customise the default attributes, the button text is automatically removed. Is there a way to prevent this, or a way to restore the original button text to the button so that it can be read? The original code when adding to a Grid is as follows:

app := tview.NewApplication()
grid := tview.NewGrid().
SetColumns(3, 45, 3).
SetRows(3,3,3,3).
AddItem(tview.NewButton("Button 1"), 0, 1, 1, 1, 0, 0, false)

I want your attention on the last line:

AddItem(tview.NewButton("Button 1"), 0, 1, 1, 1, 0, 0, false)

The moment I change the code by adding any of the following styles to tview.NewButton, the visible text, "Button 1", is deleted, as follows:

AddItem(tview.NewButton("Button 1").SetBackgroundColor(tcell.ColorWhite), 0, 1, 1, 1, 0, 0, false). - Any color substituted has the same effect.

Or,

AddItem(tview.NewButton("Button 1").SetBorder(true), 0, 1, 1, 1, 0, 0, false). - Also removes the visible text, "Button 1", from the button object.

Is there a remedy for this issue?

WhipMeharder

Originally created by @WhipMeHarder on GitHub (Nov 16, 2023). Original GitHub issue: https://github.com/rivo/tview/issues/916 Hello Any/All, I have written some very simple code to test adding buttons to a tview Grid. However, when I try to change or customise the default attributes, the button text is automatically removed. Is there a way to prevent this, or a way to restore the original button text to the button so that it can be read? The original code when adding to a Grid is as follows: `app := tview.NewApplication()` `grid := tview.NewGrid().` `SetColumns(3, 45, 3).` `SetRows(3,3,3,3).` ` AddItem(tview.NewButton("Button 1"), 0, 1, 1, 1, 0, 0, false) ` I want your attention on the last line: ` AddItem(tview.NewButton("Button 1"), 0, 1, 1, 1, 0, 0, false) ` The moment I change the code by adding any of the following styles to tview.NewButton, the visible text, "Button 1", is deleted, as follows: `AddItem(tview.NewButton("Button 1").SetBackgroundColor(tcell.ColorWhite), 0, 1, 1, 1, 0, 0, false). ` - Any color substituted has the same effect. Or, `AddItem(tview.NewButton("Button 1").SetBorder(true), 0, 1, 1, 1, 0, 0, false). ` - Also removes the visible text, "Button 1", from the button object. Is there a remedy for this issue? WhipMeharder
kerem closed this issue 2026-03-04 01:06:55 +03:00
Author
Owner

@rivo commented on GitHub (Nov 16, 2023):

SetBackgroundColor() returns a Box, not a Button. Some details on this here: https://pkg.go.dev/github.com/rivo/tview#hdr-Type_Hierarchy

The solution would be something like this:

button := tview.NewButton("Button 1")
button.SetBackgroundColor( ... )
grid.AddItem(button, ... )
<!-- gh-comment-id:1814330451 --> @rivo commented on GitHub (Nov 16, 2023): `SetBackgroundColor()` returns a `Box`, not a `Button`. Some details on this here: https://pkg.go.dev/github.com/rivo/tview#hdr-Type_Hierarchy The solution would be something like this: ```go button := tview.NewButton("Button 1") button.SetBackgroundColor( ... ) grid.AddItem(button, ... ) ```
Author
Owner

@WhipMeHarder commented on GitHub (Nov 16, 2023):

Ok. Yes! This works! The reason being, that chaining functions which belong to the same primitive may not necessarily be a subclass of it.

<!-- gh-comment-id:1814780373 --> @WhipMeHarder commented on GitHub (Nov 16, 2023): Ok. Yes! This works! The reason being, that chaining functions which belong to the same primitive may not necessarily be a subclass of it.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/tview#668
No description provided.