亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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)文章

最新評論