main.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package main
  2. import (
  3. "fmt"
  4. "fyne.io/fyne/v2"
  5. "fyne.io/fyne/v2/app"
  6. "fyne.io/fyne/v2/container"
  7. "fyne.io/fyne/v2/widget"
  8. )
  9. func main() {
  10. myApp := app.New()
  11. myWindow := myApp.NewWindow("下载工具")
  12. myWindow.Resize(fyne.NewSize(800, 600))
  13. // 创建输入框
  14. ipEntry := widget.NewEntry()
  15. ipEntry.SetText("127.0.0.1")
  16. ipEntry.Resize(fyne.NewSize(200, ipEntry.MinSize().Height))
  17. portEntry := widget.NewEntry()
  18. portEntry.SetText("7890")
  19. ipEntry.Resize(fyne.NewSize(150, ipEntry.MinSize().Height))
  20. // 创建输出框
  21. outputText := widget.NewMultiLineEntry()
  22. outputText.SetPlaceHolder("输出将显示在这里...")
  23. outputText.Wrapping = fyne.TextWrapWord
  24. // 创建按钮
  25. urlButton := widget.NewButton("下载URL", func() {
  26. ip := ipEntry.Text
  27. port := portEntry.Text
  28. // 在输出框中显示信息
  29. outputText.SetText(fmt.Sprintf("开始下载URL - IP: %s, Port: %s\n%s", ip, port, outputText.Text))
  30. // 调用UrlDownloader函数
  31. UrlDownloader(ip, port, outputText)
  32. })
  33. imgButton := widget.NewButton("下载图片", func() {
  34. ip := ipEntry.Text
  35. port := portEntry.Text
  36. // 在输出框中显示信息
  37. outputText.SetText(fmt.Sprintf("开始下载图片 - IP: %s, Port: %s\n%s", ip, port, outputText.Text))
  38. // 调用ImgDownloader函数
  39. ImgDownloader(ip, port, outputText)
  40. })
  41. clearButton := widget.NewButton("清除输出", func() {
  42. outputText.SetText("")
  43. })
  44. // 创建滚动容器用于输出框
  45. scrollContainer := container.NewScroll(outputText)
  46. scrollContainer.SetMinSize(fyne.NewSize(400, 400))
  47. // 布局
  48. // 左侧按钮容器
  49. leftPanel := container.NewVBox(
  50. urlButton,
  51. imgButton,
  52. clearButton,
  53. widget.NewLabel(""), // 空标签用于间隔
  54. )
  55. // 顶部输入框容器
  56. inputPanel := container.NewHBox(
  57. widget.NewLabel("IP:"),
  58. ipEntry,
  59. widget.NewLabel("端口:"),
  60. portEntry,
  61. )
  62. // 主布局:顶部是输入框,中间是左右分栏
  63. content := container.NewBorder(
  64. inputPanel, // 顶部
  65. nil, // 底部
  66. leftPanel, // 左侧
  67. nil, // 右侧
  68. scrollContainer, // 中间
  69. )
  70. myWindow.SetContent(content)
  71. myWindow.ShowAndRun()
  72. }