今天开始学习一下tkinter,制作一下电话簿下载功能
目录
一、完整代码
import tkinter as tk
from tkinter import ttk
import time
window = tk.Tk()
# 设置窗口的标题
window.title("电话号码下载")
# 设置窗口的尺寸大小
window.geometry("800x500")
# 设定是否能够改变窗口大小的尺寸
window.resizable(True, True)
# 是否能够关闭窗口
# root.destroy()
fr1 = tk.Frame(window).pack()
lab1 = tk.Label(fr1, text="Telephone Number", font=28).pack()
text1 = tk.Text(fr1, width=50, height=10)
text1.pack()
# 获取text文本中的数据
def getTextInput():
progress['value'] = 0
msg_list = []
result = text1.get("1.0", "end")
msg = result.split('\n')
# 处理字符串里的数字
for m in msg:
if m.isdigit():
msg_list.append(m)
# 计算步长
step = int(100 / len(msg_list)+1)
for i in range(0, len(msg_list)):
progress['value'] += step
text2.insert("insert", msg_list[i] + '\n')
# 更新UI确保进度条的变化立即反映出来
window.update_idletasks()
time.sleep(1)
print(msg_list)
but = tk.Button(window, text="执行", height=1, width=10, command=getTextInput).pack(pady=10)
fr2 = tk.Frame(window).pack()
lab2 = tk.Label(fr2, text="Load Telephone", font=28).pack()
text2 = tk.Text(fr2, width=50, height=10)
text2.pack()
lab3 = tk.Label(fr2, text="进度条", font=28).pack(pady=20)
progress = tk.ttk.Progressbar(window, length=400, mode='determinate', orient=tk.HORIZONTAL)
progress.pack()
# 为了循环显示窗口
window.mainloop()
二、效果展示
标签:text,list,ttk,window,tk,msg,电话簿,下载,pack From: https://blog.csdn.net/weixin_58573288/article/details/140614836每一步的代码备注都有写上,欢迎大家来学习和借鉴!!!