我正在嘗試調整此(清單)的大小,因為它只顯示一行,第二個看到它需要向下捲動我想顯示多行,這是程式碼:-
"fyne.io/fyne/v2/app" "fyne.io/fyne/v2/container" "fyne.io/fyne/v2/widget" type CustomList struct { Header fyne.CanvasObject List *widget.List } a := app.New() // Create a new window w := a.NewWindow("Resources Manager") // Create a list with five columns list = widget.NewList( func() int { return len(clientInfos) }, func() fyne.CanvasObject { return container.NewHBox(widget.NewIcon(nil), widget.NewLabel("")) }, func(index int, obj fyne.CanvasObject) { c := obj.(*fyne.Container) icon := c.Objects[0].(*widget.Icon) label := c.Objects[1].(*widget.Label) // load the image resource img, err := fyne.LoadResourceFromPath(clientInfos[index].Country) if err != nil { fmt.Println("Failed to load image", err) return } // set image to icon and text to label icon.SetResource(img) label.SetText(fmt.Sprintf("%s | %s | %s | %s | %s", clientInfos[index].AppName, clientInfos[index].Version, clientInfos[index].kerenl, clientInfos[index].Price, clientInfos[index].Size, )) label.TextStyle = fyne.TextStyle{Bold: true, Italic: false, Monospace: true} }, ) list.OnSelected = func(id int) { selectedID = id } customList := &CustomList{ Header: widget.NewLabel("Icon | AppName | kerenl | Price | Size | Status"), List: list, } customList.List.Resize(fyne.Size{Height: 434}) // Create a container for the buttons buttonContainer := container.NewVBox() buttonContainer.Add(widget.NewButton("Install", func() { // Handle button click })) buttonContainer.Add(widget.NewButton("download", func() { // Handle button click })) buttonContainer.Add(widget.NewButton("Upgrade", func() { // Handle button click })) buttonContainer.Add(widget.NewButton("Refresh", func() { list.Refresh() // Handle button click })) buttonContainer.Resize(fyne.NewSize(230, 300)) vbox := container.NewVBox( customList.Header, customList.List, ) vbox.Resize(fyne.NewSize(600, 320)) horizontalSplit := container.NewHSplit(vbox, buttonContainer) horizontalSplit.SetOffset(0.8) content := container.NewVBox(horizontalSplit, textArea) w.SetContent(content) w.Resize(fyne.NewSize(800, 270)) w.ShowAndRun()
還有其他用於 gui 的 Golang 函式庫嗎?因為看起來大多數都已經過時了,對嗎?然而,我真的需要一些更簡單的東西來建立一個GUI,例如
正確答案
#在fyne 中,小部件被放入容器中,並且該容器通常具有佈局。如果您進行了此設置,那麼您對 Resize
的手動呼叫將被所選佈局覆蓋。
VBox 的使用正是這樣做的,因為它的演算法希望使每個項目盡可能短。
請改用邊框,標題位於頂部,清單佔用剩餘空間。
Fyne 中的物件總是填滿分配給它們的空間,但要使其執行您想要的操作,選擇正確的容器/佈局非常重要。 https://www.php.cn/link/4d6ce445727ef59cc07abb95d3e4a1d4
#以上是golang fyne gui 無法調整列表大小的詳細內容。更多資訊請關注PHP中文網其他相關文章!

Gohandlesinterfacesandtypeassertionseffectively,enhancingcodeflexibilityandrobustness.1)Typeassertionsallowruntimetypechecking,asseenwiththeShapeinterfaceandCircletype.2)Typeswitcheshandlemultipletypesefficiently,usefulforvariousshapesimplementingthe

Go語言的錯誤處理通過errors.Is和errors.As函數變得更加靈活和可讀。 1.errors.Is用於檢查錯誤是否與指定錯誤相同,適用於錯誤鏈的處理。 2.errors.As不僅能檢查錯誤類型,還能將錯誤轉換為具體類型,方便提取錯誤信息。使用這些函數可以簡化錯誤處理邏輯,但需注意錯誤鏈的正確傳遞和避免過度依賴以防代碼複雜化。

tomakegoapplicationsRunfasterandMorefly,useProflingTools,leverageConCurrency,andManageMoryfectily.1)usepprofforcpuorforcpuandmemoryproflingtoidentifybottlenecks.2)upitizegorizegoroutizegoroutinesandchannelstoparalletaparelalyizetasksandimproverperformance.3)

go'sfutureisbrightwithtrendslikeMprikeMprikeTooling,仿製藥,雲 - 納蒂維德象,performanceEnhancements,andwebassemblyIntegration,butchallengeSinclainSinClainSinClainSiNgeNingsImpliCityInsImplicityAndimimprovingingRornhandRornrorlling。

goroutinesarefunctionsormethodsthatruncurranceingo,啟用效率和燈威量。 1)shememanagedbodo'sruntimemultimusingmultiplexing,允許千sstorunonfewerosthreads.2)goroutinessimproverentimensImproutinesImproutinesImproveranceThroutinesImproveranceThrountinesimproveranceThroundinesImproveranceThroughEasySytaskParallowalizationAndeff

purposeoftheInitfunctionoIsistoInitializeVariables,setUpConfigurations,orperformneccesSetarySetupBeforEtheMainFunctionExeCutes.useInitby.UseInitby:1)placingitinyourcodetorunautoamenationally oneraty oneraty oneraty on inity in ofideShortAndAndAndAndForemain,2)keepitiTshortAntAndFocusedonSimImimpletasks,3)

Gointerfacesaremethodsignaturesetsthattypesmustimplement,enablingpolymorphismwithoutinheritanceforcleaner,modularcode.Theyareimplicitlysatisfied,usefulforflexibleAPIsanddecoupling,butrequirecarefulusetoavoidruntimeerrorsandmaintaintypesafety.

在Go中使用recover()函數可以從panic中恢復。具體方法是:1)在defer函數中使用recover()捕獲panic,避免程序崩潰;2)記錄詳細的錯誤信息以便調試;3)根據具體情況決定是否恢復程序執行;4)謹慎使用,以免影響性能。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

SecLists
SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。

SublimeText3漢化版
中文版,非常好用

Dreamweaver Mac版
視覺化網頁開發工具