Toolbar icons- Fyne GUI Golang tutorial 65

Toolbar icons- Fyne GUI Golang tutorial 65

Fyne Toolbar widget is another fyne Golang example and tutorial.

fyne widgets are very easy to use but without proper fyne documentation it may not be easy.

Yesterday we covered fyne table which is an amazing fyne widget to create tables.

 

 

<div>
<div>package main</div>
<div>// import fyne</div>
<div>import (</div>
<div>    "fmt"</div>
<div>    "fyne.io/fyne/v2"</div>
<div>    "fyne.io/fyne/v2/app"</div>
<div>    "fyne.io/fyne/v2/container"</div>
<div>    "fyne.io/fyne/v2/theme"</div>
<div>    "fyne.io/fyne/v2/widget"</div>
<div>)</div>
<div>func main() {</div>
<div>    // new app</div>
<div>    a := app.New()</div>
<div>    // new title and window</div>
<div>    w := a.NewWindow("Tool bar - music player ui")</div>
<div>    // resize main window</div>
<div>    w.Resize(fyne.NewSize(400, 400))</div>
<div>    // new widget---- Tool bar</div>
<div>    toolbar := widget.NewToolbar(</div>
<div>        //toolbar items</div>
<div>        widget.NewToolbarAction(</div>
<div>            // first argument is icon</div>
<div>            // 2nd is action/func(){}</div>
<div>            theme.MediaPlayIcon(), func() {</div>
<div>                fmt.Println("Play music...")</div>
<div>            },</div>
<div>        ),</div>
<div>        // copy paste for other items</div>
<div>        // pause</div>
<div>        widget.NewToolbarAction(</div>
<div>            // first argument is icon</div>
<div>            // 2nd is action/func(){}</div>
<div>            theme.MediaPauseIcon(), func() {</div>
<div>                fmt.Println("Pause music...")</div>
<div>            },</div>
<div>        ),</div>
<div>        widget.NewToolbarAction(</div>
<div>            // first argument is icon</div>
<div>            // 2nd is action/func(){}</div>
<div>            theme.MediaStopIcon(), func() {</div>
<div>                fmt.Println("Stop music...")</div>
<div>            },</div>
<div>        ),</div>
<div>        // spacer widget</div>
<div>        widget.NewToolbarSpacer(),</div>
<div>        // new item for support</div>
<div>        /// copy paste</div>
<div>        widget.NewToolbarAction(</div>
<div>            // first argument is icon</div>
<div>            // 2nd is action/func(){}</div>
<div>            theme.HelpIcon(), func() {</div>
<div>                fmt.Println("support music...")</div>
<div>            },</div>
<div>        ),</div>
<div>    )</div>
<div>    // put everthing in a container</div>
<div>    // c := container.NewHBox(toolbar)</div>
<div>    // letss change container</div>
<div>    c := container.NewBorder(</div>
<div>        // 5 elements / arguments</div>
<div>        // top, right,left,bottom, center</div>
<div>        toolbar, nil, nil, nil, widget.NewLabel("Content here"),</div>
<div>    )</div>
<div>    w.SetContent(c)</div>
<div>    w.ShowAndRun()</div>
<div>}</div>
</div>

 

Download Code

Fyne Golang GUI Course

 

Tony BB
 

TonyBB is a Coach , marketer, hypnotist and a founder of RSKVF Production who specializes in providing simple, affordable, and easy to use solutions for Life.

Click Here to Leave a Comment Below 0 comments

Leave a Reply: