GO GUI help (walk package)

huangapple go评论86阅读模式
英文:

GO GUI help (walk package)

问题

我正在为我的应用程序制作一个GUI,使用了lxn/walk包。
我正在尝试弄清楚如何按像素放置元素。我的代码如下:

package main

import (
	"github.com/lxn/walk"
	. "github.com/lxn/walk/declarative"
)

var edit *walk.Label

func main() {

	MainWindow{
		Title:   "FetchTest",
		MinSize: Size{600, 400},
		Layout:  VBox{},

		Children: []Widget{

			Label{
				AssignTo: &edit,
				Text:     "Hello",
			},

			PushButton{
				Text: "GET DATA",
				OnClicked: func() {

				},
			},
		},
	}.Run()

	edit.SetBounds(walk.Rectangle{10, 5, 50, 50})

}

但是这段代码不起作用,因为设置标签位置的代码没有执行。
在哪里使用edit.SetBounds(walk.Rectangle{10, 5, 50, 50},以便元素显示在给定的坐标上?

英文:

I am making a GUI for my app, using package lxn/walk.
I'm trying to figure out how to place elements by pixels. My code is like this:

package main

import (
	"github.com/lxn/walk"
	. "github.com/lxn/walk/declarative"
)

var edit *walk.Label

func main() {

	MainWindow{
		Title:   "FetchTest",
		MinSize: Size{600, 400},
		Layout:  VBox{},

		Children: []Widget{

			Label{
				AssignTo: &edit,
				Text:     "Hello",
			},

			PushButton{
				Text: "GET DATA",
				OnClicked: func() {
					
				},
			},
		},
	}.Run()

	edit.SetBounds(walk.Rectangle{10, 5, 50, 50})

}

But this doesn't work since the code that sets the position of label is not executing.
Where to use edit.SetBounds(walk.Rectangle{10, 5, 50, 50} so the element is shown at the given coordinates?

答案1

得分: 3

我对walk不太熟悉,但也许MainWindow.Run()只有在窗口关闭时才会返回?你可以尝试一下walk "filebrowser"示例中使用的方法:调用Create来设置窗口,进行任何额外的初始化,然后调用Run

英文:

I'm not familiar with walk, but maybe MainWindow.Run() only returns when the window is closed? You could try the approach used in the walk "filebrowser" example: call Create to set up the window, do any additional initialization, and then call Run.

huangapple
  • 本文由 发表于 2016年2月19日 21:45:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/35506842.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定