Creating a Feedback Form with Fyne in Go

In this video, I demonstrate how to create a simple feedback form using the Fyne library in Go. Follow along as I explain the code step-by-step, showing you how to set up an entry widget for user input, a submit button, and a feedback label to display messages. This tutorial is perfect for beginners looking to learn more about Go and the Fyne library. Don’t forget to like, comment, and subscribe for more programming tutorials!

STEP:1 Main package
package main

STEP:2 Import all fyne packages
import (
“fyne.io/fyne/v2” // Importing fyne package for GUI
“fyne.io/fyne/v2/app” // Importing fyne app package
“fyne.io/fyne/v2/container” // Importing fyne container package for layout
“fyne.io/fyne/v2/widget” // Importing fyne widget package for UI elements
)

STEP:3 create main function

func main() {}

STEP:4 Creating a new Fyne application
a := app.New()

STEP:5 Creating a new window with the title “Feedback Messages Example”
w := a.NewWindow(“Feedback Messages Example”)

STEP:6 Create an entry widget for user input
entry := widget.NewEntry()

STEP:7 Setting a placeholder text for the entry widget
entry.SetPlaceHolder(“Enter some text…”)

STEP:8 Create a label for feedback messages. Initializing an empty label to display feedback messages
feedbackLabel := widget.NewLabel(“”)

STEP:9 Create a button to submit the form. Creating a submit button with a click handler
submitButton := widget.NewButton(“Submit”, func() {

STEP:10 Check if the entry widget is not empty
if entry.Text != “” {

// Display success message
feedbackLabel.SetText(“Your data has been saved successfully!”)

} else {
// Display error message
feedbackLabel.SetText(“Please enter some text before submitting.”)

}
})

STEP:11 Organize components in a vertical box layout. Adding the entry widget, submit button, and feedback label to the vertical box layout
w.SetContent(container.NewVBox(entry,
submitButton,
feedbackLabel,
))

STEP:12 Resize the window to 400×400 pixels
w.Resize(fyne.NewSize(400, 400))

STEP:13 Display the window and start the application
w.ShowAndRun()

 

SOURCE CODE

// Main package
package main

Import all fyne packages
import (
    "fyne.io/fyne/v2"           // Importing fyne package for GUI
    "fyne.io/fyne/v2/app"       // Importing fyne app package
    "fyne.io/fyne/v2/container" // Importing fyne container package for layout
    "fyne.io/fyne/v2/widget"    // Importing fyne widget package for UI elements
)

func main() {
// Creating a new Fyne application
    a := app.New() 
	
// Creating a new window with the title "Feedback Messages Example"	
    w := a.NewWindow("Feedback Messages Example") 

    // Create an entry widget for user input
    entry := widget.NewEntry()
	
// Setting a placeholder text for the entry widget	
    entry.SetPlaceHolder("Enter some text...") 

    // Create a label for feedback messages
	// Initializing an empty label to display feedback messages
    feedbackLabel := widget.NewLabel("") 


    // Create a button to submit the form
	// Creating a submit button with a click handler
    submitButton := widget.NewButton("Submit", func() { 
	
	// Check if the entry widget is not empty
        if entry.Text != "" { 
		
		// Display success message
            feedbackLabel.SetText("Your data has been saved successfully!") 
			
        } else {
		// Display error message
            feedbackLabel.SetText("Please enter some text before submitting.") 
			
        }
    })

// Organize components in a vertical box layout
// Adding the entry widget, submit button, and feedback label to the vertical box layout
    w.SetContent(container.NewVBox( 

        entry,
        submitButton,
        feedbackLabel,
    ))
	// Resize the window to 400x400 pixels
    w.Resize(fyne.NewSize(400, 400)) 
	
	// Display the window and start the application
    w.ShowAndRun() 
	
}

Hashtags: #GoLang #FyneLibrary #Programming #CodingTutorial #GoProgramming #GUI #SoftwareDevelopment #FeedbackForm #TechTutorial #LearnProgramming

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: