go gtk3開發之Grid布局控制項 15

2021-10-04 04:55:45 字數 3736 閱讀 5478

建立grid布局控制項。

// table布局已經取消

func

main()

)if err !=

nilrun

(os.args)

}func

createwindow

// 獲取window視窗

winobj,

_:= builder.

getobject

("window1"

) window := winobj.

(*gtk.window)

addwindow

(window)

// window 視窗設定

window.

setsizerequest

(300

,240

)//設定視窗大小

window.

settitle

("hello go"

)//設定標題

window.

setresizable

(false

)//設定不可伸縮

window.

setposition

(gtk.win_pos_center)

//設定居中顯示

err = window.

seticonfromfile()

//設定icon

if err !=

nil//獲取布局控制項

tableobj, err := builder.

getobject

("grid1"

)if err !=

nil fmt.

println

("tableobj"

, reflect.

typeof

(tableobj)

) table := tableobj.

(*gtk.grid)

button,

_:= gtk.

buttonnewwithlabel

("新按鈕"

)//新建按鈕

table.

attach

(button,2,

3,2,

3)//指定位置新增控制項 - 失敗

// 顯示所有介面

window.

showall()

}

<?xml version="1.0" encoding="utf-8"?>

>

class

="gtkwindow"

id="window1"

>

name

="can_focus"

>

falseproperty

>

>

class

="gtkgrid"

id="grid1"

>

name

="visible"

>

trueproperty

>

name

="can_focus"

>

falseproperty

>

>

/>

child

>

>

/>

child

>

>

/>

child

>

>

/>

child

>

>

/>

child

>

>

/>

child

>

>

/>

child

>

>

class

="gtkbutton"

id="button1"

>

name

="label"

translatable

="yes"

>

buttonproperty

>

name

="visible"

>

trueproperty

>

name

="can_focus"

>

trueproperty

>

name

="receives_default"

>

trueproperty

>

object

>

>

name

="left_attach"

>

0property

>

name

="top_attach"

>

0property

>

name

="width"

>

1property

>

name

="height"

>

1property

>

packing

>

child

>

>

class

="gtkbutton"

id="button2"

>

name

="label"

translatable

="yes"

>

buttonproperty

>

name

="visible"

>

trueproperty

>

name

="can_focus"

>

trueproperty

>

name

="receives_default"

>

trueproperty

>

object

>

>

name

="left_attach"

>

1property

>

name

="top_attach"

>

1property

>

name

="width"

>

1property

>

name

="height"

>

1property

>

packing

>

child

>

object

>

child

>

object

>

inte***ce

>

go gtk3開發之垂直布局控制項 14

建立垂直布局,新版不再支援gtkhbox gtkvbox。新版不再支援gtkhbox gtkvbox glade3 3.8 編輯器太老了,使用glade 3.14 func main if err nilrun os.args func createwindow 獲取window視窗 winobj,...

go gtk3開發之水平布局控制項 13

建立水平布局,新版不再支援gtkhbox gtkvbox布局。新版不再支援gtkhbox gtkvbox glade3 3.8 編輯器太老了,使用glade 3.14 func main if err nilrun os.args func createwindow 獲取window視窗 winob...

布局管理之Grid布局

tkinter grid常用選項 column 指定將元件放入哪列,第一列的索引為 0。columnspan 指定元件橫跨多少列。row 指定元件放入哪行,第一行的索引為 0。rowspan 指定元件橫跨多少行。sticky 對齊方式,類似 pack 方法的 anchor 選項,同樣支援 n e s...