[Python][tkinter]使用Button中的command呼叫函數 Use Button Command Call Function with parameters

Veröffentlicht am: 10 April 2020
auf dem Kanal: X Workshops
538
2

This example shows how to use "command" in button to call a function with or without parameters
1. Import tkinter
2. build a window named "win".
3. window format 1: title()
4. window format 2: geometry() determine size and initial position(x,y)
5. window format 3: maxsize() set max size of a window
6. Build Label component and give a string to text
7. Build close_win function to end the window
8. Build add_label_num function to deliver paramters for increasing the text of the label and use lbl.config to change the label status
9. Build Button component and give a string to text, and use command to call the function
10. Build Button component and give a string to text, and use command to call the function with parameters
11. Use pack to arrange Button on bottom side
12. Use pack to arrange Button on left side
13. Use pack to arrange Build Label on right side
14. use mainloop() to keep window running for monitoring and handling events

這個範例說明如何使用Button中的command呼叫有參數以及無參數的函數。
#1. 引入tkinter
#2. 建立一個名為win的新視窗
#3. 視窗格式: 標題 Title()
#4. 視窗格式: 設定視窗啟動時的大小與位置 geometry("寬x長+x位移+y位移")
#5. 視窗格式: 設定視窗最大尺寸 maxsize(int長,int寬)
#6. 建立Label元件,按鍵文字 Text = "0"
#7. 建立函數close_win函數: 結束win視窗
#8. 建立函數add_label_number(num): 傳遞參數,可以增加Label中的Text數字,使用config()改變Label狀態
#9. 建立Button元件,按鍵文字 Text = "",使用command呼叫函數
#10. 建立Button元件,按鍵文字 Text = "",使用command中的lambda在按鈕事件中傳遞引數
#11. Button元件布局 pack(side='botton') 靠下
#12 Button元件布局 pack(side='left') 靠左
#13. Label元件布局 pack(side='right') 靠右
#14. mainloop()在使用者關閉視窗之前持續偵測視窗並處理事件

We will share more tutorial videos with people who want to learn LabVIEW and Python welcome to subscribe this channel.
未來會陸續更新影片,讓想學習LabVIEW和Python的朋友可以看影片學習,歡迎訂閱此頻道。

其他網址/related websites:
https://labview-tech.blogspot.com/
https://fishark.pixnet.net/blog
email: jacklee3633@gmail.com
Line: lvnet


Auf dieser Seite können Sie das Online-Video [Python][tkinter]使用Button中的command呼叫函數 Use Button Command Call Function with parameters mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer X Workshops 10 April 2020 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 538 Mal angesehen und es wurde von 2 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!