python tk研究

-- coding: UTF-8 --

import time
import threading
from tkinter import *

def update_progress_bar():
for percent in range(1, 101):
hour = int(percent / 3600)
minute = int(percent / 60) - hour * 60
second = percent % 60
green_length = int(sum_length * percent / 100)
canvas_progress_bar.coords(canvas_shape, (0, 0, green_length, 25))
canvas_progress_bar.itemconfig(canvas_text, text=’%02d:%02d:%02d’ % (hour, minute, second))
var_progress_bar_percent.set(’%0.2f %%’ % percent)
time.sleep(1)

def run():
th = threading.Thread(target=update_progress_bar)
th.setDaemon(True)
th.start()

top = Tk()
top.title(‘MML Test Project’)
top.geometry(‘700x350+290+100’)
top.resizable(False, False)
top.config(bg=’#535353’)
Label(top, text=“网元IP:”, fg=’#F5F5F5’, bg=’#535353’, font=(‘微软雅黑’, 14)).grid(row=0, column=0, sticky=E+S, pady=20)
ip = StringVar
e1 = Entry(top, textvariable=ip, font=(‘微软雅黑’, 14))
e1.grid(row=0, column=1, sticky=S, pady=20)

进度条

sum_length = 600
canvas_progress_bar = Canvas(top, width=sum_length, height=20)
canvas_shape = canvas_progress_bar.create_rectangle(0, 0, 0, 25, fill=‘green’)
canvas_text = canvas_progress_bar.create_text(280, 4, anchor=NW)
canvas_progress_bar.itemconfig(canvas_text, text=‘00:00:00’)
var_progress_bar_percent = StringVar()
var_progress_bar_percent.set(‘00.00 %’)
label_progress_bar_percent = Label(top, textvariable=var_progress_bar_percent, fg=’#F5F5F5’, bg=’#535353’)
canvas_progress_bar.grid(row=3, column=0, columnspan=2, padx=10, pady=50)
label_progress_bar_percent.grid(row=3, column=2)

按钮

button_start = Button(top, text=‘运行’, fg=’#F5F5F5’, bg=’#7A7A7A’, command=run, height=1, width=15, relief=GROOVE, bd=2,
activebackground=’#F5F5F5’, activeforeground=’#535353’)
button_start.grid(row=1, column=0, sticky=E)
button_end = Button(top, text=‘退出’, fg=’#F5F5F5’, bg=’#7A7A7A’, command=top.quit, height=1, width=15, relief=GROOVE,
bd=2, activebackground=’#F5F5F5’, activeforeground=’#535353’)
button_end.grid(row=1, column=1)

top.mainloop()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值