倒计时
import time
print('{:02}:{:02}:{:02}'.format(13,4,57))
def countdown(t):
t = int(t)
while t:
min,sec = divmod(t,60)
#print(min,sec)
timer = '{:02}:{:02}'.format(min,sec)
#print(timer)
# '{:02}:{:02}:{:02}'.format(13,4,57)
#c = f"{min}:{sec}"
print(timer)
time.sleep(1)
t -= 1
print("time's up")
t = input("Enter the times in secs秒: ")
#countdown(t)
带皮肤的数字时钟
# skin
from tkinter import *
from tkinter.ttk import *
from time import strftime
root = Tk()
root.title('Digital clock')
label = Label(root,font=('aerial',40),background='black',foreground='white')
def timer():
strs = strftime("%H:%M:%S %p")
label.config(text=strs)
label.after(1000,timer)
label.pack(anchor='center')
timer()
mainloop()
如何完成倒计时并且带有皮肤的计时器?
# Final Countdown
from tkinter import *
from tkinter.ttk import *
from time import strftime
root = Tk()
root.title('Digital clock')
label = Label(root,font=('aerial',40),background='black',foreground='white')
#label = Label(root,font=('Microsoft YaHei',40),background='dark grey',foreground='white')
def st(t):
while t >= 0:
min, sec = divmod(int(t), 60)
# print(min,sec)
strs = '{:02}:{:02}'.format(min, sec)
time.sleep(1)
t -= 1
return strs
it = iter([i for i in range(t)][::-1])
def timer():
#strs = strftime("%H:%M:%S %p")
t = next(it)
if t:
time.sleep(0.1)
label.config(text=st(t))
label.after(1000, timer)
label.pack(anchor='center')
timer()
mainloop()
倒计时停在 00:01时不动
比较流行的动态图
msedge_n4FoekCcRa.gif
import plotly.express as px
from vega_datasets import data
df = data.disasters()
df = df[df.Year > 1990]
fig = px.bar(df,
y="Entity",
x="Deaths",
animation_frame="Year",
orientation='h',
range_x=[0, df.Deaths.max()],
color="Entity")
# improve aesthetics (size, grids etc.)
fig.update_layout(width=1000,
height=800,
xaxis_showgrid=False,
yaxis_showgrid=False,
paper_bgcolor='rgba(0,0,0,0)',
plot_bgcolor='rgba(0,0,0,0)',
title_text='Evolution of Natural Disasters',
showlegend=False)
fig.update_xaxes(title_text='Number of Deaths')
fig.update_yaxes(title_text='')
fig.show()
可视化视觉比较炫的
msedge_TvvIDemjKH.gif
import plotly.express as px
df = px.data.gapminder()
fig = px.scatter(
df,
x="gdpPercap",
y="lifeExp",
animation_frame="year",
size="pop",
color="continent",
hover_name="country",
log_x=True,
size_max=55,
range_x=[100, 100000],
range_y=[25, 90],
# color_continuous_scale=px.colors.sequential.Emrld
)
fig.update_layout(width=1000,
height=800,
xaxis_showgrid=False,
yaxis_showgrid=False,
paper_bgcolor='rgba(0,0,0,0)',
plot_bgcolor='rgba(0,0,0,0)')
按国别的人口变化
网友评论