python gui tkinter快速入门教程 | python tkinter tutorial
本文首发于个人博客https://kezunlin.me/post/d5c57f56/,欢迎阅读最新内容!
python tkinter tutorial
Guide
main ui
messagebox
- showinfo()
- showwarning()
- showerror()
- askquestion()
- askokcancel()
- askyesno()
- askretrycancel()
- askyesnocancel()
filedialog
- asksaveasfilename()
- asksaveasfile()
- askopenfilename()
- askopenfile()
- askdirectory()
- askopenfilenames()
- askopenfiles()
demo
from numpy.random import seed, uniform
from numpy import uint8, uint16, load, save
from cv2 import imread, imwrite
from os import listdir, makedirs
from os.path import exists, basename
# for python 3
from tkinter import Tk, Frame, messagebox, filedialog, Button, Label, StringVar
class MyGUI():
def __init__(self):
self.root = Tk()
sw = self.root.winfo_screenwidth()
sh = self.root.winfo_screenheight()
ww = 700
wh = 200
x = (sw-ww) / 2
y = (sh-wh) / 2
self.root.title('Image Compress Tool')
# center
self.root.geometry("%dx%d+%d+%d" % (ww, wh, x, y))
# frame1
frame1 = Frame(self.root)
frame1.grid(row=0, column=0, sticky='w')
self.input_btn = Button(frame1, text="Input Folder", width=10, height=3, command=self.set_input_folder)
self.input_btn.pack(side='left')
self.input_label_text = StringVar()
self.input_label_text.set("Input Folder")
self.input_label = Label(frame1, textvariable=self.input_label_text, width=70, height=3)
self.input_label.pack(side='left')
# frame2
frame2 = Frame(self.root)
frame2.grid(row=1, column=0, sticky='w')
self.output_btn = Button(frame2, text="Output Folder", width=10, height=3, command=self.set_output_folder)
self.output_btn.pack(side='left')
self.output_label_text = StringVar()
self.output_label_text.set("Output Folder")
self.output_label = Label(frame2, textvariable = self.output_label_text, width=70, height=3)
self.output_label.pack(side='left')
# frame3
frame3 = Frame(self.root)
frame3.grid(row=2, column=0, sticky='nw')
self.run_btn = Button(frame3, text="执行加密", width=10, height=3, command=self.run_task)
self.run_btn.pack(side='left')
self.run_label_text = StringVar()
self.run_label_text.set("Ready")
self.run_label = Label(frame3, textvariable = self.run_label_text, width=70, height=3)
self.run_label.pack(side='left')
def mainloop(self):
self.root.mainloop()
def set_input_folder(self):
result = filedialog.askdirectory()
self.input_label_text.set(result)
def set_output_folder(self):
result = filedialog.askdirectory()
self.output_label_text.set(result)
def run_task(self):
input_folder = self.input_label_text.get()
output_folder = self.output_label_text.get()
#print("input_folder: "+input_folder)
#print("output_folder: "+output_folder)
if exists(input_folder):
#batch_compress(input_folder, output_folder)
self.run_label_text.set("Compress OK.")
messagebox.showinfo("Info", "Compress OK.")
else:
messagebox.showwarning("Warn", "Please input folder")
def gui():
app = MyGUI()
app.mainloop()
def main():
gui()
if __name__ =="__main__":
main()
snapshots
Reference
History
- 20190411: created.
Copyright
- Post author: kezunlin
- Post link: https://kezunlin.me/post/d5c57f56/
- Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 3.0 unless stating additionally.
python gui tkinter快速入门教程 | python tkinter tutorial的更多相关文章
- Python 数据处理库 pandas 入门教程
Python 数据处理库 pandas 入门教程2018/04/17 · 工具与框架 · Pandas, Python 原文出处: 强波的技术博客 pandas是一个Python语言的软件包,在我们使 ...
- PySide——Python图形化界面入门教程(二)
PySide——Python图形化界面入门教程(二) ——交互Widget和布局容器 ——Interactive Widgets and Layout Containers 翻译自:http://py ...
- PySide——Python图形化界面入门教程(一)
PySide——Python图形化界面入门教程(一) ——基本部件和HelloWorld 翻译自:http://pythoncentral.io/intro-to-pysidepyqt-basic-w ...
- PySide——Python图形化界面入门教程(四)
PySide——Python图形化界面入门教程(四) ——创建自己的信号槽 ——Creating Your Own Signals and Slots 翻译自:http://pythoncentral ...
- PySide——Python图形化界面入门教程(六)
PySide——Python图形化界面入门教程(六) ——QListView和QStandardItemModel 翻译自:http://pythoncentral.io/pyside-pyqt-tu ...
- PySide——Python图形化界面入门教程(五)
PySide——Python图形化界面入门教程(五) ——QListWidget 翻译自:http://pythoncentral.io/pyside-pyqt-tutorial-the-qlistw ...
- PySide——Python图形化界面入门教程(三)
PySide——Python图形化界面入门教程(三) ——使用内建新号和槽 ——Using Built-In Signals and Slots 上一个教程中,我们学习了如何创建和建立交互widget ...
- 最基础的Python的socket编程入门教程
最基础的Python的socket编程入门教程 本文介绍使用Python进行Socket网络编程,假设读者已经具备了基本的网络编程知识和Python的基本语法知识,本文中的代码如果没有说明则都是运行在 ...
- Python 绘图库Matplotlib入门教程
0 简单介绍 Matplotlib是一个Python语言的2D绘图库,它支持各种平台,并且功能强大,能够轻易绘制出各种专业的图像. 1 安装 pip install matplotlib 2 入门代码 ...
随机推荐
- <Machine Learning - 李宏毅> 学习笔记
<Machine Learning - 李宏毅> 学习笔记 b站视频地址:李宏毅2019国语 第一章 机器学习介绍 Hand crafted rules Machine learning ...
- springboot 打jar包时分离配置文件
修改pom.xml文件 <build> <resources> <resource> <directory>src/main/resources< ...
- 史上最骚最全最详细的IO流教程,没有之一!
目录 1.告白IO流的四点明确 2.File类 1.1 File概述 1.2 构造方法 1.3 常用方法 1.3.1 获取功能的方法 1.3.2 绝对路径和相对路径 1.3.3判断功能的方法 1.3. ...
- redis入门(一)
目录 redis入门(一) 前言 特性 速度快 简单稳定 丰富的功能 历史 历史版本 安装与启动 安装 数据类型与内部编码 数据结构 内部编码 常用API与使用场景 常用命令 字符串 列表 哈希 集合 ...
- 数据结构(三十二)图的遍历(DFS、BFS)
图的遍历和树的遍历类似.图的遍历是指从图中的某个顶点出发,对图中的所有顶点访问且仅访问一次的过程.通常有两种遍历次序方案:深度优先遍历和广度优先遍历. 一.深度优先遍历 深度优先遍历(Depth_Fi ...
- 第三篇 Flask中的request
每个框架中都有处理请求的机制(request),但是每个框架的处理方式和机制是不同的,下面我们来了解一下Flask的request中都有什么东西 from flask import request 1 ...
- 找不到 cucumber.api.cli.Main 的报错解决方案
最近玩IDEA,发现导入的项目有问题,报了一个“找不到或者不存在cucumber.api.cli.Main”的错误. 后来发现是新版的IDEA在导入时没有提示,以至于我没有配置项目对应的Tomcat服 ...
- 身份证号码验证算法(php和js实现)
原文:http://blog.chinaunix.net/xmlrpc.php?r=blog/article&uid=21126994&id=3938244 http://www.jb ...
- Linux性能分析
生产环境服务器变慢,诊断思路和性能评估 整机:top 代码 public class JavaDemo2 { public static void main(String[] args) { whil ...
- 基于SkyWalking的分布式跟踪系统 - 微服务监控
上一篇文章我们搭建了基于SkyWalking分布式跟踪环境,今天聊聊使用SkyWalking监控我们的微服务(DUBBO) 服务案例 假设你有个订单微服务,包含以下组件 MySQL数据库分表分库(2台 ...