| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- package main
- import (
- "fmt"
- "fyne.io/fyne/v2"
- "fyne.io/fyne/v2/app"
- "fyne.io/fyne/v2/container"
- "fyne.io/fyne/v2/widget"
- )
- func main() {
- myApp := app.New()
- myWindow := myApp.NewWindow("下载工具")
- myWindow.Resize(fyne.NewSize(800, 600))
- // 创建输入框
- ipEntry := widget.NewEntry()
- ipEntry.SetText("127.0.0.1")
- ipEntry.Resize(fyne.NewSize(200, ipEntry.MinSize().Height))
- portEntry := widget.NewEntry()
- portEntry.SetText("7890")
- ipEntry.Resize(fyne.NewSize(150, ipEntry.MinSize().Height))
- // 创建输出框
- outputText := widget.NewMultiLineEntry()
- outputText.SetPlaceHolder("输出将显示在这里...")
- outputText.Wrapping = fyne.TextWrapWord
- // 创建按钮
- urlButton := widget.NewButton("下载URL", func() {
- ip := ipEntry.Text
- port := portEntry.Text
- // 在输出框中显示信息
- outputText.SetText(fmt.Sprintf("开始下载URL - IP: %s, Port: %s\n%s", ip, port, outputText.Text))
- // 调用UrlDownloader函数
- UrlDownloader(ip, port, outputText)
- })
- imgButton := widget.NewButton("下载图片", func() {
- ip := ipEntry.Text
- port := portEntry.Text
- // 在输出框中显示信息
- outputText.SetText(fmt.Sprintf("开始下载图片 - IP: %s, Port: %s\n%s", ip, port, outputText.Text))
- // 调用ImgDownloader函数
- ImgDownloader(ip, port, outputText)
- })
- clearButton := widget.NewButton("清除输出", func() {
- outputText.SetText("")
- })
- // 创建滚动容器用于输出框
- scrollContainer := container.NewScroll(outputText)
- scrollContainer.SetMinSize(fyne.NewSize(400, 400))
- // 布局
- // 左侧按钮容器
- leftPanel := container.NewVBox(
- urlButton,
- imgButton,
- clearButton,
- widget.NewLabel(""), // 空标签用于间隔
- )
- // 顶部输入框容器
- inputPanel := container.NewHBox(
- widget.NewLabel("IP:"),
- ipEntry,
- widget.NewLabel("端口:"),
- portEntry,
- )
- // 主布局:顶部是输入框,中间是左右分栏
- content := container.NewBorder(
- inputPanel, // 顶部
- nil, // 底部
- leftPanel, // 左侧
- nil, // 右侧
- scrollContainer, // 中间
- )
- myWindow.SetContent(content)
- myWindow.ShowAndRun()
- }
|