python_tkinter彈出對話框創(chuàng)建2
更新時間:2022年03月20日 11:12:10 作者:手可摘星辰。
這篇文章主要介紹了python_tkinter彈出對話框創(chuàng)建,上以篇文章我們簡單的對對話框創(chuàng)建做了簡單介紹,本文將繼續(xù)更多相關內容,需要的小伙伴可以參考一下
上一篇相關文章python_tkinter彈出對話框創(chuàng)建需要的可以參考一下
1.fledialog對話框
示例:askopenfilename(選擇單個文件,獲取文件路徑)
import tkinter # 導入消息對話框子模塊 import tkinter.filedialog # 創(chuàng)建主窗口 root = tkinter.Tk() # 設置窗口大小 root.minsize(300,300) # 創(chuàng)建函數 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() # 設置窗口大小 root.minsize(300,300) # 創(chuàng)建函數 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() # 設置窗口大小 root.minsize(300,300) # 創(chuàng)建函數 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() # 設置窗口大小 root.minsize(300,300) # 創(chuàng)建函數 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() # 設置窗口大小 root.minsize(300,300) # 創(chuàng)建函數 def color(): ? ? # 選擇顏色 ? ? ? ? ? ? ?默認定位顏色 ? ? ruselt = tkinter.colorchooser.askcolor(color = 'red') ? ? # 返回一個元組(rgb顏色,十六進制顏色) ? ? print(ruselt) # 添加按鈕 btn = tkinter.Button(root,text = '選擇顏色',command = color) btn.pack() # 加入消息循環(huán) root.mainloop()
到此這篇關于python_tkinter彈出對話框創(chuàng)建2的文章就介紹到這了,更多相關tkinter對話框內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
關于torch.scatter與torch_scatter庫的使用整理
這篇文章主要介紹了關于torch.scatter與torch_scatter庫的使用整理,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-09-09