我在 Flet 中的上一個專案需要實作 DatePicker。我們來看看 Flet 官方文件提供的範例。
import datetime import flet as ft def main(page: ft.Page): page.horizontal_alignment = ft.CrossAxisAlignment.CENTER def handle_change(e): page.add(ft.Text(f"Date changed: {e.control.value.strftime('%Y-%m-%d')}")) def handle_dismissal(e): page.add(ft.Text(f"DatePicker dismissed")) page.add( ft.ElevatedButton( "Pick date", icon=ft.icons.CALENDAR_MONTH, on_click=lambda e: page.open( ft.DatePicker( first_date=datetime.datetime(year=2023, month=10, day=1), last_date=datetime.datetime(year=2024, month=10, day=1), on_change=handle_change, on_dismiss=handle_dismissal, ) ), ) ) ft.app(main)
文件沒有闡明 first_date 和 last_date 屬性是否在每次執行應用程式時預設更新。假設我們編譯了一個應用程序,並且 first_date 和 last_date 參數保留為前面的程式碼,這在將來選擇有效日期時會產生錯誤嗎?
我的應用程式旨在抓取兩個特定日期之間的 X (Twitter)。當希望使其直觀且易於使用時(作為已編譯和可執行的應用程式),在檢查程式碼時,我問自己如果參數first_date 和last_date 保持值會發生什麼在編寫應用程式時分配。如果一年後,有人想到昨天,他們能做到嗎?如何確保參數是動態的,以便從執行時間開始計算時間?
有疑問時,我是這樣解決的:
import datetime import flet as ft # Crear una variable para la fecha actual de la ejecución today = datetime.datetime.now() def main(page: ft.Page): page.horizontal_alignment = ft.CrossAxisAlignment.CENTER def handle_change(e): page.add(ft.Text(f"Date changed: {e.control.value.strftime('%Y-%m-%d')}")) def handle_dismissal(e): page.add(ft.Text(f"DatePicker dismissed")) page.add( ft.ElevatedButton( "Pick date", icon=ft.icons.CALENDAR_MONTH, on_click=lambda e: page.open( ft.DatePicker( # Configuramos las variables para que un calendario válido desde hace un año a hoy y durante un año a futuro first_date=datetime.datetime(year=today.year - 1, month=today.month, day=today.day), last_date=datetime.datetime(year=today.year + 1, month=today.month, day=today.day), on_change=handle_change, on_dismiss=handle_dismissal, ) ), ) ) ft.app(main)
透過這種方式,我們確保無論應用程式執行的時刻(編譯與否),日曆中的可選日期都將具有可配置的時間記錄,以執行本身作為初始參數。
此方法對於實現需要限制可選擇日期的特定功能也很有用,例如僅允許選擇到日期,因為選擇未來的日期是沒有意義的。
例如,在我的抓取應用程式中,當任務是收集過去的資訊時,允許配置未來的日期有什麼意義?
以上是在 Flet 中處理 DatePicker的詳細內容。更多資訊請關注PHP中文網其他相關文章!

Pythonarrayssupportvariousoperations:1)Slicingextractssubsets,2)Appending/Extendingaddselements,3)Insertingplaceselementsatspecificpositions,4)Removingdeleteselements,5)Sorting/Reversingchangesorder,and6)Listcomprehensionscreatenewlistsbasedonexistin

NumPyarraysareessentialforapplicationsrequiringefficientnumericalcomputationsanddatamanipulation.Theyarecrucialindatascience,machinelearning,physics,engineering,andfinanceduetotheirabilitytohandlelarge-scaledataefficiently.Forexample,infinancialanaly

useanArray.ArarayoveralistinpythonwhendeAlingwithHomoGeneData,performance-Caliticalcode,orinterfacingwithccode.1)同質性data:arraysSaveMemorywithTypedElements.2)績效code-performance-calitialcode-calliginal-clitical-clitical-calligation-Critical-Code:Arraysofferferbetterperbetterperperformanceformanceformancefornallancefornalumericalical.3)

不,notalllistoperationsareSupportedByArrays,andviceversa.1)arraysdonotsupportdynamicoperationslikeappendorinsertwithoutresizing,wheremactsperformance.2)listssdonotguaranteeconecontanttanttanttanttanttanttanttanttanttimecomplecomecomplecomecomecomecomecomecomplecomectacccesslectaccesslecrectaccesslerikearraysodo。

toAccesselementsInapythonlist,useIndIndexing,負索引,切片,口頭化。 1)indexingStartSat0.2)否定indexingAccessesessessessesfomtheend.3)slicingextractsportions.4)iterationerationUsistorationUsisturessoreTionsforloopsoreNumeratorseforeporloopsorenumerate.alwaysCheckListListListListlentePtotoVoidToavoIndexIndexIndexIndexIndexIndExerror。

Arraysinpython,尤其是Vianumpy,ArecrucialInsCientificComputingfortheireftheireffertheireffertheirefferthe.1)Heasuedfornumerericalicerationalation,dataAnalysis和Machinelearning.2)Numpy'Simpy'Simpy'simplementIncressionSressirestrionsfasteroperoperoperationspasterationspasterationspasterationspasterationspasterationsthanpythonlists.3)inthanypythonlists.3)andAreseNableAblequick

你可以通過使用pyenv、venv和Anaconda來管理不同的Python版本。 1)使用pyenv管理多個Python版本:安裝pyenv,設置全局和本地版本。 2)使用venv創建虛擬環境以隔離項目依賴。 3)使用Anaconda管理數據科學項目中的Python版本。 4)保留系統Python用於系統級任務。通過這些工具和策略,你可以有效地管理不同版本的Python,確保項目順利運行。

numpyarrayshaveseveraladagesoverandastardandpythonarrays:1)基於基於duetoc的iMplation,2)2)他們的aremoremoremorymorymoremorymoremorymoremorymoremoremory,尤其是WithlargedAtasets和3)效率化,效率化,矢量化函數函數函數函數構成和穩定性構成和穩定性的操作,製造


熱AI工具

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

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

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

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

熱門文章

熱工具

SublimeText3 Linux新版
SublimeText3 Linux最新版

MinGW - Minimalist GNU for Windows
這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。

Atom編輯器mac版下載
最受歡迎的的開源編輯器

mPDF
mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),

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