python_tkinter彈出對話框創(chuàng)建2
更新時間:2022年03月20日 11:12:10 作者:手可摘星辰。
這篇文章主要介紹了python_tkinter彈出對話框創(chuàng)建,上以篇文章我們簡單的對對話框創(chuàng)建做了簡單介紹,本文將繼續(xù)更多相關(guān)內(nèi)容,需要的小伙伴可以參考一下
上一篇相關(guān)文章python_tkinter彈出對話框創(chuàng)建需要的可以參考一下
1.fledialog對話框
示例:askopenfilename(選擇單個文件,獲取文件路徑)

import tkinter # 導入消息對話框子模塊 import tkinter.filedialog # 創(chuàng)建主窗口 root = tkinter.Tk() # 設(shè)置窗口大小 root.minsize(300,300) # 創(chuàng)建函數(shù) def filename(): ? ? # 獲取文件路徑 ? ? path = tkinter.filedialog.askopenfilename() ? ? print(path) # 添加按鈕 btn = tkinter.Button(root,text = '文件',command = filename) btn.pack() # 加入消息循環(huán) root.mainloop()
示例:askopenfilenames(選擇多個文件,獲取文件路徑)
用法和上面單個文件一樣!返回一個元組,包含每個文件的路徑
示例:askopenfile(打開文件獲取單個文件指針,具有open()的作用)

import tkinter # 導入消息對話框子模塊 import tkinter.filedialog # 創(chuàng)建主窗口 root = tkinter.Tk() # 設(shè)置窗口大小 root.minsize(300,300) # 創(chuàng)建函數(shù) def file(): ? ? # 獲取文件路徑 ? ? fp = tkinter.filedialog.askopenfile(mode = 'r') ? ? print(fp) # 添加按鈕 btn = tkinter.Button(root,text = '文件',command = file) btn.pack() # 加入消息循環(huán) root.mainloop()
示例:askopenfiles(打開文件獲取多個文件指針,具有open()的作用)
用法和上面單個文件一樣!
示例:askdirectory(獲取一個文件夾的路徑)

import tkinter # 導入消息對話框子模塊 import tkinter.filedialog # 創(chuàng)建主窗口 root = tkinter.Tk() # 設(shè)置窗口大小 root.minsize(300,300) # 創(chuàng)建函數(shù) def dir(): ? ? # 獲取文件夾路徑 ? ? path = tkinter.filedialog.askdirectory() ? ? print(path) # 添加按鈕 btn = tkinter.Button(root,text = '文件夾',command = dir) btn.pack() # 加入消息循環(huán) root.mainloop()
示例:asksaveasfilename (選擇保存文件的路徑)

import tkinter # 導入消息對話框子模塊 import tkinter.filedialog # 創(chuàng)建主窗口 root = tkinter.Tk() # 設(shè)置窗口大小 root.minsize(300,300) # 創(chuàng)建函數(shù) def saves(): ? ? # 選擇保存文件路徑 ? ? path = tkinter.filedialog.asksaveasfilename() ? ? print(path) # 添加按鈕 btn = tkinter.Button(root,text = 'saves',command = saves) btn.pack() # 加入消息循環(huán) root.mainloop()
2.顏色選擇對話框
示例:askcolor

import tkinter # 導入消息對話框子模塊 import tkinter.colorchooser # 創(chuàng)建主窗口 root = tkinter.Tk() # 設(shè)置窗口大小 root.minsize(300,300) # 創(chuàng)建函數(shù) def color(): ? ? # 選擇顏色 ? ? ? ? ? ? ?默認定位顏色 ? ? ruselt = tkinter.colorchooser.askcolor(color = 'red') ? ? # 返回一個元組(rgb顏色,十六進制顏色) ? ? print(ruselt) # 添加按鈕 btn = tkinter.Button(root,text = '選擇顏色',command = color) btn.pack() # 加入消息循環(huán) root.mainloop()
到此這篇關(guān)于python_tkinter彈出對話框創(chuàng)建2的文章就介紹到這了,更多相關(guān)tkinter對話框內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Python史上最全種類數(shù)據(jù)庫操作方法分享
本文將詳細探討如何在Python中連接全種類數(shù)據(jù)庫以及實現(xiàn)相應的CRUD(創(chuàng)建,讀取,更新,刪除)操作,文中的示例代碼講解詳細,需要的可以參考一下2023-07-07
Pearson相關(guān)系數(shù)和Spearman相關(guān)系數(shù)的區(qū)別及說明
這篇文章主要介紹了Pearson相關(guān)系數(shù)和Spearman相關(guān)系數(shù)的區(qū)別及說明,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-05-05
python實現(xiàn)圖片數(shù)據(jù)增強的示例詳解
這篇文章主要為大家詳細介紹了python實現(xiàn)圖片數(shù)據(jù)增強的相關(guān)知識,文中的示例代碼講解詳細,具有一定的學習價值,感興趣的小伙伴可以跟隨小編一起了解一下2023-10-10

