- 对话框,无cgo https://github.com/ncruces/zenity
go get github.com/ncruces/zenity@latest
文档 https://pkg.go.dev/github.com/ncruces/zenity
//选择单文件 返回string
file, _ := zenity.SelectFile(
zenity.Filename(""),
zenity.Title("选择文件"),
zenity.FileFilters{
{"Go文件", []string{"*.go"}, false},
{"web文件", []string{"*.html", "*.js", "*.css"}, true},
{"图片文件", []string{"*.png", "*.gif", "*.ico", "*.jpg", "*.webp"}, true},
})
//文件夹选择单选/多选
f, _ := zenity.SelectFileMultiple(zenity.Title("选择文件夹"), zenity.Directory())
f, _ := zenity.SelectFile(zenity.Title("选择文件夹"), zenity.Directory())
//选择多文件 返回 []string
file, _ := zenity.SelectFileMultiple(zenity.FileFilters{
{"图片", []string{"*.png", "*.gif", "*.ico", "*.jpg", "*.webp"}, false},
})
//选择日期 返回time.time
file, _ := zenity.Calendar("选择日期")
//颜色框
i, _ := zenity.SelectColor(zenity.ShowPalette())
//输入框
file, _ := zenity.Entry("请输入用户", zenity.Title("对话框标题"), zenity.OKLabel("确定"), zenity.CancelLabel("取消"), zenity.Width(800))
//进度条
dlg, _ := zenity.Progress(zenity.Title("更新信息..."), zenity.NoCancel(), zenity.OKLabel("确定"))
defer dlg.Close()
dlg.Text("0%")
dlg.Value(0)
time.Sleep(time.Second)
dlg.Text("100%")
dlg.Value(100)
time.Sleep(time.Second * 20)
dlg.Complete()
//提示,错误
zenity.Info("提示信息", zenity.Title("标题"))
zenity.Error("错误", zenity.Title("标题"), zenity.Width(400))
zenity.Warning("警告", zenity.Title("警告"))
err := zenity.Question("询问", zenity.Title("询问"), zenity.DefaultCancel())
if err == nil {
fmt.Print("你按了确定")
} else {
fmt.Print("取消")
}
//右下角通知
zenity.Notify("右下角提示弹出", zenity.Title("提示信息"), zenity.InfoIcon)
//列表框,单选
i, _ := zenity.List("选择", []string{"中国", "日本", "韩国"}, zenity.Title("标题"), zenity.OKLabel("确定"), zenity.CancelLabel("取消"), zenity.DisallowEmpty(), zenity.DefaultItems("日本"))
//多选
i, _ := zenity.ListMultiple("多选", []string{"apples", "oranges", "bananas", "strawberries"}, zenity.Title("标题"), zenity.OKLabel("确定"), zenity.CancelLabel("取消"), zenity.DisallowEmpty())
//密码框
u, p, _ := zenity.Password(zenity.Title("登录"), zenity.OKLabel("确定"), zenity.CancelLabel("取消"), zenity.Username())
fmt.Print(u, "密码", p)
//保存对话框
f, err := zenity.SelectFileSave(zenity.Title("保存文件"), zenity.ConfirmOverwrite(), zenity.Filename("12"), zenity.FileFilters{{"Go files", []string{"*.go"}, false}, {"Web files", []string{"*.html", "*.js", "*.css"}, true}, {"Image files", []string{"*.png", "*.gif", "*.ico", "*.jpg", "*.webp"}, true}})
if err == nil {
fmt.Print(f)
} else {
fmt.Print("取消")
}
- tk无cgo https://gitlab.com/cznic/tk9.0
文档 https://pkg.go.dev/modernc.org/tk9.0`
go
package main
import (
_ “embed”
“fmt”
. “modernc.org/tk9.0”
“modernc.org/tk9.0/b5”
“os”
“runtime”
“time”
)
func main() {
fmt.Println(“hello world”)
background := White
blue := b5.Colors{b5.ButtonText: “#fff”, b5.ButtonFace: “#0d6efd”, b5.ButtonFocus: “#98c1fe”}
red := b5.Colors{b5.ButtonText: “#fff”, b5.ButtonFace: “#dc3545”, b5.ButtonFocus: “#f0a9b0”}
green := b5.Colors{b5.ButtonText: “#fff”, b5.ButtonFace: “#198754”, b5.ButtonFocus: “#9dccb6”}
StyleThemeUse(“default”)
opts := Opts{Padx(“1m”), Pady(“2m”), Ipadx(“1m”), Ipady(“1m”)}
Grid(TButton(Txt(“blue”), Style(b5.ButtonStyle(“blue.TButton”, blue, background, false))),
TButton(Txt(“red”), Style(b5.ButtonStyle(“red.TButton”, red, background, false))),
TButton(Txt(“绿色”), Style(b5.ButtonStyle(“green.TButton”, green, background, false))),
opts)
menubar := Menu()
uhome, _ := os.UserHomeDir()
fileMenu := menubar.Menu()
fileMenu.AddCommand(Lbl(“Open…”), Underline(0), Accelerator(“Ctrl+O”), Command(func() { GetOpenFile() }))
Bind(App, “
fileMenu.AddSeparator()
fileMenu.AddCommand(Lbl(“保存”), Command(func() {
GetSaveFile(
Title(“Save File”),
Confirmoverwrite(true),
Filetypes([]FileType{{“Go files”, []string{“.go”}, “”}}))
}))
fileMenu.AddCommand(Lbl(“Exit”), Underline(1), Accelerator(“Ctrl+Q”), ExitHandler())
Bind(App, “
menubar.AddCascade(Lbl(“File”), Underline(0), Mnu(fileMenu))
editMenu := menubar.Menu()
editMenu.AddCommand(Lbl("选择颜色"), Command(func() {
co := ChooseColor(Title("选择颜色"), Initialcolor("red"))
fmt.Println(co)
}))
editMenu.AddCommand(Lbl("选择目录"), Command(func() {
co := ChooseDirectory(Initialdir(uhome))
fmt.Println(co)
}))
editMenu.AddCommand(Lbl("剪贴板"), Command(func() {
s := ClipboardGet()
fmt.Println(s)
}))
editMenu.AddCommand(Lbl("Select All"))
menubar.AddCascade(Lbl("Edit"), Underline(0), Mnu(editMenu))
helpMenu := menubar.Menu()
helpMenu.AddCommand(Lbl("Help Index"))
helpMenu.AddCommand(Lbl("About..."))
menubar.AddCascade(Lbl("Help"), Underline(0), Mnu(helpMenu))
lbl := Label()
NewTicker(100*time.Millisecond, func() {
lbl.Configure(Txt(time.Now().Format(time.DateTime)))
})
Grid(TLabel(Txt("测试"), State("disabled"), Width(10)), TExit(Txt("退出")),
Button(Txt("单机"), Command(func() {
Destroy(App) //退出
})), lbl, TButton(Txt("单机"), Command(func() {
Focus(TEntry(Textvariable("foo")))
})), TButton(Txt("打开文件"), Command(func() {
s := GetOpenFile(
Title("打开文件"),
Initialdir(uhome),
Multiple(true),
Filetypes([]FileType{{"Go 文件", []string{".go"}, ""}}))
fmt.Println(s)
})),
opts)
Grid(TButton(Txt("消息"), Command(func() {
s := MessageBox(Title("消息"), Detail("信息"), Type("okcancel"))
fmt.Println(s)
})),
TCombobox(Values("")), TEntry(Textvariable("默认值"), Width(20)),
TCheckbutton(Txt("是否"), Command(func() {
fmt.Println(1)
MessageBox(Icon("error"), Msg("woui我是"), Title("Error"))
})),
Radiobutton(Txt("单选,2")),
opts)
App.WmTitle(fmt.Sprintf("我是标题%s on %s", App.WmTitle(""), runtime.GOOS))
Bind(App, "<Control-f>", Command(func() { fmt.Println("Clicked!") }))
App.Configure(Mnu(menubar), Width("8c"), Height("6c"), Background(background)).Center().Wait()
}
`
- govcl https://github.com/ying32/govcl
- wails
go install github.com/wailsapp/wails/v2/cmd/wails@latest
wails doctor
wails init -n myproject -t svelte
wails init -n myproject -t vue
wails dev
wails build