icon 字幕
正在載入字幕...

Fyne Getting Started: Updating Content

youtube 翻譯 youtube 中文翻譯 youtube 字幕 youtube 中文字幕 youtube 翻譯成中文 youtube 視頻翻譯 youtube translate to chinese translate youtube to chinese youtube transcript to chinese translate youtube video to chinese

YouTube transcript, YouTube translate

32/32

A quick preview of the first subtitles so you know what the video covers.

hello and welcome to another fine tutorial in this installment we're going to be building on the concept of the user interface and looking at how we can update content that's already displayed so we're going to start from the hello world code from a previous tutorial and work from there to begin this tutorial i've copied the files from the previous hello world you can see here we have the module definition and the sum file along with main.go so if we open our files in visual studio code again you'll see the code as it was in our hello world tutorial previously this time we're going to want to make something a bit more dynamic so let's make a clock that displays in a similar window so we will change the title of our window to clock and we're going to want to update this label here so instead of saying hello world it displays the time now the key part about updating content is to be able to reference it using a variable name so instead of passing it anonymously into set content we want to extract it from here and set up a new variable so we will call this clock and we will simply pass the label in and then we pass the variable into set content now this would execute exactly like it did before but we want to do something a little bit more and so instead of setting static text here we'll create a new function that is able to update the time we'll call this update time i will pass in a clock widget and so we need to create this new function update time and the item that we're passing in is going to be our widget dot label and inside this function we're going to want to make sure that it's displaying the correct time to use this we'll get the formatted time using the so we can get the formatted time using time.now and then the format function and let's just save that so it imports the time package and we can get some hints and the format takes a format string and to display hours minute seconds we use the helper of three for the hours four for the minutes and five for the seconds and because this is a format string we could add more things like the time is and so we have a formatted time string and to update the display we just call set text

設定

100%

翻譯目標語言

🔊 音訊播放
正在播放翻譯音訊