英文:
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
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论