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 入门代码 ...
随机推荐
- ESP8266开发之旅 基础篇② 如何安装ESP8266的Arduino开发环境
授人以鱼不如授人以渔,目的不是为了教会你具体项目开发,而是学会学习的能力.希望大家分享给你周边需要的朋友或者同学,说不定大神成长之路有博哥的奠基石... QQ技术互动交流群:ESP8266&3 ...
- TextBox各种设置
前台: <StackPanel> <TextBlock Margin=" TextWrapping="Wrap"> TextBlock with ...
- Javascript进阶必会
概念: 局部块函数声明: ES5才承认有这个东西. function f(){return 'global';} function test(x){ var result = []; if(x) { ...
- 怎么在.NetCore3.0 中使用Log4net 写日志 及读取配置文件的信息
1:安装Log4Net的 NuGet 包: 我们通常之需要安装这一个包即可,其他的主包会自动被添加进来: insatll-package Microsoft.Extensions.Logging.L ...
- Springboot与任务整合(四)
一 异步任务 启动类 @MapperScan("com.topcheer.*.*.dao") @SpringBootApplication @EnableCaching @Enab ...
- li列表循环滚动的简单方法,无需插件,简单方法搞定
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- ABAP中将Unicode字符串转换成中文的方法
以下为示例代码: DATA: LV_UNICODE TYPE STRING, "Unicode字符串 LV_CHINESE TYPE STRING. ...
- 在虚拟机上的关于Apache(阿帕奇)(3)基于IP访问网站
这篇随笔是基于IP访问网站,和后面两篇文章基于域名和基于端口一起练习效果更好 基于IP(记得下载httpd服务) 首先使用nmtui命令为网卡添加多个ip地址 输入命令:nmtui 进入下面这个界 ...
- 【XSY2131】【BZOJ1857】【SCOI2010】传送带
Description 题目描述: 在一个二维平面上有两条传送带,每一条传送带可以看成是一条线段.两条传送带分别为线段AB和线段CD.小y在AB上的移动速度为P,在CD上的移动速度为Q,在平面上的移动 ...
- CSPS模拟99
555我原型笔录 T1 不会线段树维护单调栈被dalao们踩爆 T2 我要实现这样一个东西: 已知a,b,c,使a=a-b,b=b-c 结果我把代码弄成这样: b=b-c;a=a-b; 然后就被dal ...