其他分享
首页 > 其他分享> > 【毕设日记】(3)go语言基于gopacket+fyne简单抓包工具实现之GUI

【毕设日记】(3)go语言基于gopacket+fyne简单抓包工具实现之GUI

作者:互联网

PkgList.go 渲染包的简要信息的list和对应的说明信息

package ui

import (
	"fmt"
	fyne2 "fyne.io/fyne/v2"
	"fyne.io/fyne/v2/container"
	"fyne.io/fyne/v2/data/binding"
	"fyne.io/fyne/v2/widget"
	//"time"
)
func loadPkgList(w fyne2.Window) (*fyne2.Container,binding.StringList) {
	pkgText:=[]string{
		"No.     ","Time                          ","Source              ","Dst                      ",
		"Protocol   ","Length     ","Info                                 ",
	}
	pkgTextContainer:=container.NewHBox()
	for _,v:=range pkgText{
		pkgTextContainer.Add(widget.NewButton(v, func() {

		}))
	}
	PkgStringList:=binding.NewStringList()

	PkgList:=widget.NewListWithData(PkgStringList,
		func() fyne2.CanvasObject {
			return widget.NewLabel("")
		},
		func(item binding.DataItem, object fyne2.CanvasObject) {
			i:=item.(binding.String)
			l:=object.(*widget.Label)
			s,_:=i.Get()
			l.SetText(s)
		})
	PkgList.OnSelected= func(id widget.ListItemID) {
		fmt.Println(id)

	}
	s:=widget.NewSeparator()
	PkgInfoContainer:=container.NewBorder(pkgTextContainer,nil,nil,s,PkgList)
	PkgInfoContainer.Resize(fyne2.NewSize(1600,280))
	return PkgInfoContainer,PkgStringList

}

效果:在这里插入图片描述

标签:widget,毕设,io,fyne,gopacket,binding,fyne2,func
来源: https://blog.csdn.net/qq_44631559/article/details/121872900