Creating Structured Headers and Titles with Fyne in Go

In this tutorial, I walk you through creating a well-structured graphical user interface (GUI) with headers and titles using the Fyne library in Go. We’ll explore how to set up a new Fyne application, add bold and centered main titles, create section headers, and organize content labels. By the end of this tutorial, you’ll have a clear understanding of how to design an organized and visually appealing GUI with Fyne. Don’t forget to like, comment, and subscribe for more Go programming tutorials!

 

STEP:1 Define the main package.
package main
STEP:2 import all fyne packages
import (
    “fyne.io/fyne/v2”
    “fyne.io/fyne/v2/app”
    “fyne.io/fyne/v2/container”
    “fyne.io/fyne/v2/widget”
)
STEP:3 Define the main function
func main() {}
STEP:4 Creating a new fyne application
    a := app.New()
STEP:5 Creating a new window with the title “Headers and titles example”
    w := a.NewWindow(“Headers and titles example”)
STEP:6 Main title
    mainTitle := widget.NewLabel(“Welcome to My Application”)
    mainTitle.TextStyle = fyne.TextStyle{Bold: true}
    mainTitle.Alignment = fyne.TextAlignCenter
STEP:7 Section headers
    sectionHeader1 := widget.NewLabel(“Section 1: Overview”)
    sectionHeader1.TextStyle = fyne.TextStyle{Bold: true}
    sectionHeader2 := widget.NewLabel(“Section 2: Details”)
    sectionHeader2.TextStyle = fyne.TextStyle{Bold: true}
STEP:8 Content labels
    contentLabel1 := widget.NewLabel(“This is the overview section where you can find general informaiton”)
    contentLabel2 := widget.NewLabel(“This is the overview section where you can find general informaiton”)
STEP:9 Organize component in a vertical box layout
    content := container.NewVBox(mainTitle,
        widget.NewSeparator(),
        sectionHeader1, contentLabel1,widget.NewSeparator(),
        sectionHeader2, contentLabel2,)
STEP:10 set content    
    w.SetContent(content)
STEP:11 Set window size
    w.Resize(fyne.NewSize(400, 400))
STEP:12 set content on screen
    w.CenterOnScreen()
STEP:13 Display the window and start the application
    w.ShowAndRun()

SOURCE CODE:

// Define the main package.
package main
//import all fyne packages
import (
	"fyne.io/fyne/v2"
    "fyne.io/fyne/v2/app"
    "fyne.io/fyne/v2/container"
    "fyne.io/fyne/v2/widget"
)

//Define the main function
func main() {
	// your code here
	//Creating a new fyne application
	a := app.New()
	//Creating a new window with the title 
	//"Headers and titles example"
	w := a.NewWindow("Headers and titles example")
	// Main title
	mainTitle := widget.NewLabel("Welcome to My Application")
	mainTitle.TextStyle = fyne.TextStyle{Bold: true}
	mainTitle.Alignment = fyne.TextAlignCenter

	//Section headers
	sectionHeader1 := widget.NewLabel("Section 1: Overview")
	sectionHeader1.TextStyle = fyne.TextStyle{Bold: true}

	sectionHeader2 := widget.NewLabel("Section 2: Details")
	sectionHeader2.TextStyle = fyne.TextStyle{Bold: true}

	// Content labels
	contentLabel1 := widget.NewLabel("This is the overview section where you can find general informaiton")
	contentLabel2 := widget.NewLabel("This is the overview section where you can find general informaiton")

	// I made a mistake. lets fix it.
	//Organize component in a vertical box layout
	content := container.NewVBox(mainTitle, 
		widget.NewSeparator(), 
		sectionHeader1, contentLabel1,widget.NewSeparator(), 
		sectionHeader2, contentLabel2,)
	
	w.SetContent(content)
	// Set window size
	w.Resize(fyne.NewSize(400, 400))
	//set content on screen
	w.CenterOnScreen()
	// Display the window and start the application
	w.ShowAndRun()
	// I made some mistake, lets fix it.
}

 

#GoLang #FyneLibrary #Programming #CodingTutorial #GoProgramming #GUI #SoftwareDevelopment #HeadersAndTitles #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: