python的tkinter编程(十五)弹出颜色框,文件对话框

2020-11-20 15:05:33 浏览数 (3)

代码语言:javascript复制
from tkinter.colorchooser import askcolor


from tkinter import *
from tkinter import messagebox




root = Tk()
root.geometry("400x200 200 300")
root.title("测试")
def text1():
    s1 = askcolor(color="red",title="背景色")
    print(s1)  #  ((0.0, 255.99609375, 64.25), '#00ff40')
    # s1[1]  = (0.0, 255.99609375, 64.25)
    root.config(bg = s1[1])

Button(root,text="jj",command=text1).pack()

root.mainloop()

文件对话框

代码语言:javascript复制
# ,filetypes=[("视频文件",".mp4")]
def text2():  返回的f是文件的全路径
    f= askopenfilename(title="上传文件",initialdir="f:")
    print(f)

def text3():   读文件里面的内容
    with askopenfile(title="上传文件",initialdir="f:") as f:
        print(f.read())

Button(root,text="jj",command=text1).pack()
Button(root,text="rr",command=text2).pack()
Button(root,text="rr",command=text3).pack()

0 人点赞