Contact Form Mutliline Entry Resize – Fyne Golang GUI Tutorial 51

Contact Form Mutliline Entry Resize – Fyne Golang GUI Tutorial 51

Another fyne & Golang tutorial for you guys

Contact Form fyne

In this tutorial we are going to create UI of contact form.

We are going to create form which get name, email , address and message from user and a submit button.

Mutliline Entry Resize in fyne

In previous tutorials we have discussed, how to resize entry, button, label etc. Now we are going to reszie multiline entry in this episode.

Text Wrapping in fyne Mutliline Entry

I forgot to use text wrapping. Here is the code if you need text wrapping

entry_msg.Wrapping = fyne.TextWrapBreak

 

Vidoe of Contact form in fyne

Source Code

<div>
<div>package main</div>
<div>// import fyne</div>
<div>import (</div>
<div>    "image/color"</div>
<div>    "fyne.io/fyne/v2"</div>
<div>    "fyne.io/fyne/v2/app"</div>
<div>    "fyne.io/fyne/v2/canvas"</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 and title</div>
<div>    w := a.NewWindow("Contact form &amp; Resize widgets")</div>
<div>    // Resize window</div>
<div>    w.Resize(fyne.NewSize(400, 400))</div>
<div>    // title of our form</div>
<div>    title := canvas.NewText("Contact Us", color.Black)</div>
<div>    title.TextSize = 20 // text font size is 20</div>
<div>    title.TextStyle = fyne.TextStyle{Bold: true}</div>
<div>    // I need it bold.. you can make it italic</div>
<div>    title.Resize(fyne.NewSize(300, 35)) // 300 is width &amp; 35 is height</div>
<div>    title.Move(fyne.NewPos(50, 10))</div>
<div>    //position my widget</div>
<div>    //50 px from left and 10 px from top</div>
<div>    // copy / the setting(resize/ postion)</div>
<div>    // Name field</div>
<div>    entry_name := widget.NewEntry()</div>
<div>    entry_name.SetPlaceHolder("Enter your name..")</div>
<div>    entry_name.Resize(fyne.NewSize(300, 35))</div>
<div>    entry_name.Move(fyne.NewPos(50, 50))</div>
<div>    // copy / paste for next widget email :)</div>
<div>    entry_email := widget.NewEntry()</div>
<div>    entry_email.SetPlaceHolder("Enter your email..")</div>
<div>    entry_email.Resize(fyne.NewSize(300, 35))</div>
<div>    entry_email.Move(fyne.NewPos(50, 100))</div>
<div>    // copy / paste for address</div>
<div>    entry_addr := widget.NewEntry()</div>
<div>    entry_addr.SetPlaceHolder("Enter your addr..")</div>
<div>    entry_addr.Resize(fyne.NewSize(300, 35))</div>
<div>    entry_addr.Move(fyne.NewPos(50, 150))</div>
<div>    // copy/ paste for last widget</div>
<div>    entry_msg := widget.NewMultiLineEntry()</div>
<div>    entry_msg.SetPlaceHolder("Enter your message..")</div>
<div>    // most important</div>
<div>    entry_msg.MultiLine = true // multiline input / text area for message</div>
<div>    entry_msg.Resize(fyne.NewSize(300, 140))</div>
<div>    entry_msg.Move(fyne.NewPos(50, 200))</div>
<div>    // Submit button</div>
<div>    submit_btn := widget.NewButton("SUBMIT", nil)</div>
<div>    submit_btn.Resize(fyne.NewSize(80, 30))</div>
<div>    // button need to be small as compared to textarea</div>
<div>    submit_btn.Move(fyne.NewPos(50, 355))</div>
<div>    // setup content</div>
<div>    // we are going to use container without layout// my favorite</div>
<div>    w.SetContent(</div>
<div>        container.NewWithoutLayout(</div>
<div>            title,</div>
<div>            entry_name,</div>
<div>            entry_email,</div>
<div>            entry_addr,</div>
<div>            entry_msg,</div>
<div>            submit_btn,</div>
<div>        ),</div>
<div>    )</div>
<div>    // Show and run</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: