博客
关于我
Python GUI tkinter库 自学20
阅读量:277 次
发布时间:2019-03-01

本文共 1109 字,大约阅读时间需要 3 分钟。

颜色框 文件选择框及读取文件内容

1、颜色框

from tkinter import *from tkinter.colorchooser import *window = Tk()window.geometry("500x200")def test1():    s1 = askcolor(color="red", title="选择背景色")    print(s1)    # s1 的值是:((255.99609375, 0.0, 0.0), '#ff0000')    window.config(bg=s1[1])Button(window, text="选择背景色", command=test1).pack()window.mainloop()

2、文件选择框

from tkinter import *from tkinter.filedialog import *window = Tk()window.geometry("500x200")def test1():    f1 = askopenfilename(title="上传文件",                         initialdir="d:", filetypes=[("视频文件", ".mp4")])    # print(f1)    show["text"] = f1Button(window, text="选择编辑的视频文件", command=test1).pack()show = Label(window, width=10, height=5, bg="green")show.pack()window.mainloop()

3、读取文件内容

from tkinter import *from tkinter.filedialog import *window = Tk()window.geometry("500x200")def test1():    with askopenfile(title="上传文件",                     initialdir="d:", filetypes=[("文本文件", ".txt")]) as f:        show["text"] = f.read()Button(window, text="选择读取的文本文件", command=test1).pack()show = Label(window, width=10, height=5, bg="green")show.pack()window.mainloop()

转载地址:http://wkho.baihongyu.com/

你可能感兴趣的文章
Nginx - 反向代理、负载均衡、动静分离、底层原理(案例实战分析)
查看>>
Nginx - 反向代理与负载均衡
查看>>
nginx 1.24.0 安装nginx最新稳定版
查看>>
nginx 301 永久重定向
查看>>
nginx 403 forbidden
查看>>
nginx connect 模块安装以及配置
查看>>
nginx css,js合并插件,淘宝nginx合并js,css插件
查看>>
Nginx gateway集群和动态网关
查看>>
nginx http配置说明,逐渐完善。
查看>>
Nginx keepalived一主一从高可用,手把手带你一步一步配置!
查看>>
Nginx Location配置总结
查看>>
Nginx log文件写入失败?log文件权限设置问题
查看>>
Nginx Lua install
查看>>
nginx net::ERR_ABORTED 403 (Forbidden)
查看>>
vue中处理过内存泄露处理方法
查看>>
Nginx RTMP 模块使用指南
查看>>
Nginx SSL 性能调优
查看>>
Nginx SSL私有证书自签,且反代80端口
查看>>
Nginx upstream性能优化
查看>>
Nginx 中解决跨域问题
查看>>