Resize Entry, Button – Fyne GUI Golang tutorial 50

Resize Entry, Button – Fyne GUI Golang tutorial 50

 

Fyne Resize Entry

Create New Entry/Input widget
entry := widget.NewEntry()

Set place holder Text
entry.SetPlaceHolder(“Enter your name”)

Resize widget Size
entry.Resize(fyne.NewSize(250, 30))

Position of widget on parent window
entry.Move(fyne.NewPos(40, 50))

Fyne Resize Button

Create a Button and Set button label. Here “submit” is my button label

btn_submit := widget.NewButton("Submit", nil) 

Resize button size according to your needs.

 btn_submit.Resize(fyne.NewSize(150, 30)) 

Set position of your button on parent window

 btn_submit.Move(fyne.NewPos(40, 200))   

 

Source Code

<div>
<div>package main</div>
<div>// import fyne</div>
<div>import (</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/widget"</div>
<div>)</div>
<div>func main() {</div>
<div>    // New app</div>
<div>    a := app.New()</div>
<div>    // New Window &amp; title</div>
<div>    w := a.NewWindow("Resize any widget")</div>
<div>    //Resize main/parent window</div>
<div>    w.Resize(fyne.NewSize(400, 400))</div>
<div>    // 1st Widget Entry</div>
<div>    entry := widget.NewEntry()</div>
<div>    entry.SetPlaceHolder("Enter your name")</div>
<div>    entry.Resize(fyne.NewSize(250, 30)) // my widget size</div>
<div>    entry.Move(fyne.NewPos(40, 50))     // position of widget</div>
<div>    entry_email := widget.NewEntry()</div>
<div>    entry_email.SetPlaceHolder("Enter your email")</div>
<div>    entry_email.Resize(fyne.NewSize(250, 30)) // my widget size</div>
<div>    entry_email.Move(fyne.NewPos(40, 100))    // position of widget</div>
<div>    entry_address := widget.NewEntry()</div>
<div>    entry_address.SetPlaceHolder("Enter your name")</div>
<div>    entry_address.Resize(fyne.NewSize(250, 30)) // my widget size</div>
<div>    entry_address.Move(fyne.NewPos(40, 150))    // position of widget</div>
<div>    // button</div>
<div>    btn_submit := widget.NewButton("Submit", nil)</div>
<div>    btn_submit.Resize(fyne.NewSize(150, 30)) // my widget size</div>
<div>    btn_submit.Move(fyne.NewPos(40, 200))    // position of widget</div>
<div>    w.SetContent(</div>
<div>        container.NewWithoutLayout(</div>
<div>            entry,</div>
<div>            entry_email,</div>
<div>            entry_address,</div>
<div>            btn_submit,</div>
<div>        ),</div>
<div>    )</div>
<div>    //show and run</div>
<div>    w.ShowAndRun()</div>
<div>}</div>
</div>

 

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: