python Windows tkinter應用開發1建立初始頁面

圖片.png
- ofollow,noindex">python測試開發專案實戰-目錄
- python工具書籍下載-持續更新
- python 3.7極速入門教程 - 目錄
歡迎來到python Windows tkinter應用開發第一章,我們將開始建立一個應用程式,它刪除計算機資料夾中的重複檔案。該專案將使用tkinter模組,它是python 3的標準庫。
第一章非常簡單,我們將建立一個按鈕,當點選時它將開啟檔案選擇器視窗,允許我們從資料夾中選擇檔案。
本教程要求具備python基礎。
程式碼:
from tkinter import * from tkinter import filedialog win = Tk() # 1 Create instance win.title("Multitas") # 2 Add a title win.resizable(0, 0) # 3 Disable resizing the GUI # 4 Create a label aLabel = Label(win, text="Remove duplicate file") aLabel.grid(column=0, row=0) # 5 Position the label # 6 Create a selectFile function to be used by button def selectFile(): filename = filedialog.askopenfilename(initialdir="/", title="Select file") print(filename) # 7 print the filename from the selected file # 8 Adding a Button action = Button(win, text="Search File", command=selectFile) action.grid(column=0, row=1) # 9 Position the button win.mainloop()# 10 start GUI
執行:

image
選擇檔案之後,會在打印出選擇的檔名:
參考資料
- 討論qq群144081101 567351477
- 本文最新版本地址
- 本文涉及的python測試開發庫 謝謝點贊!
- 本文相關海量書籍下載
- python工具書籍下載-持續更新
- python GUI工具書籍下載-持續更新

image