做的不好,谅解一下(做了一周)
import ttkbootstrap as ttk
from ttkbootstrap.dialogs import Messagebox
import psutil,time,threading,webbrowser,ctypes,os,random
from ttkbootstrap.constants import *
from tkinter.filedialog import askopenfilename
root=ttk.Window(title='',alpha=0.7)
root.resizable(False,False)
root.wm_attributes('-topmost',1)
def lea():
os.system("shutdown -s -t 0")
def da():
path = askopenfilename()
path = path.replace('/',"\ ")
path = path.replace(' ',"")
os.startfile(path)
if not path:
return
def u1():
ttk.Label(root,text='').bind(webbrowser.open("https://hao.360.com/?hj=llq2c"))
def u2():
ttk.Label(root,text='').bind(webbrowser.open("https://www.baidu.com/"))
#m1
menubar = ttk.Menu(root)
def a1():
Messagebox.show_info(title='提示', message='暂无')
def a2():
import user_1
filemenu = ttk.Menu(menubar)
menubar.add_cascade(label='使用', menu=filemenu)
filemenu.add_command(label='退出', command=root.destroy)
filemenu.add_command(label='关机', command=lea)
submenu=ttk.Menu(filemenu)
submenu.add_command(label="360导航",command=u1)
submenu.add_command(label="百度",command=u2)
filemenu.add_cascade(label='打开', menu=submenu, underline=0)
filemenu.add_separator()
def w1():
Messagebox.okcancel(title='帮助',message='暂无')
help = ttk.Menu(menubar,tearoff=0)
menubar.add_cascade(label='帮助', menu=help)
help.add_command(label='帮助', command=w1)
root.config(menu=menubar)
f = ttk.Frame(root)
f.pack(pady=5, fill=X, side=TOP)
nb = ttk.Notebook(f)
nb.pack(side=LEFT,padx=(10, 0),expand=YES,fill=BOTH)
#m2
t1= ttk.Frame(nb)
ttk.Button(t1,text="360导航", bootstyle=SUCCESS,command=u1).pack()
ttk.Button(t1,text="百度",command=u2,bootstyle=(PRIMARY, "outline-toolbutton")).pack()
nb.add(t1, text='打开网站')
t2= ttk.Frame(nb)
ttk.Button(t2, text="打开本地文件", command=da).pack(fill=X, padx=10, pady=10)
nb.add(t2,text='打开文件')
t3= ttk.Frame(nb)
ttk.Label(t3, text="输入你的公式:").pack()
da_content = ttk.StringVar()
da=ttk.Entry(t3, textvariable=da_content).pack()
def t3a():
da1=eval("int("+da_content.get()+")")
da2="你要的答案是"+str(da1)
Messagebox.okcancel(message=da2)
ttk.Button(t3,text="求和",command=t3a).pack()
nb.add(t3,text='计算器')
t4= ttk.Frame(nb)
ttk.Label(t4, text="最大上限:").pack()
upn_content = ttk.StringVar()
upn=ttk.Entry(t4, textvariable=upn_content).pack()
ttk.Label(t4, text="最小下限:").pack()
don_content = ttk.StringVar()
don=ttk.Entry(t4, textvariable=don_content).pack()
def t4a():
t4_1=int(upn_content.get())
t4_2=int(don_content.get())
t4_3=random.randint(t4_2,t4_1)
t4_4="随机数:"+str(t4_3)
Messagebox.okcancel(message=t4_4)
ttk.Button(t4,text="随机",command=t4a).pack()
nb.add(t4,text='随机数')
t5= ttk.Frame(nb)
ttk.Text(t5,).pack(padx=1,pady=1,fill=BOTH)
ttk.Label(t5, text="注:文本不保存").pack()
nb.add(t5,text='记事本')
#m3
def _():
meter = ttk.Meter(metersize=180,padding=50,amountused=0,metertype="semi",subtext="当前网速(kB/s)",subtextstyle="warning",interactive=False,bootstyle='primary',)
meter.pack()
while True:
meter.configure(amountused=round(getNet(),2))
def getNet():
recv_before = psutil.net_io_counters().bytes_recv
time.sleep(1)
recv_now = psutil.net_io_counters().bytes_recv
recv = (recv_now - recv_before)/1024
return recv
t = threading.Thread(target=_)
t.setDaemon(True)
t.start()
#m4
style = ttk.Style()
theme_names = style.theme_names()
theme_selection = ttk.Frame(root, padding=(10, 10, 10, 0))
theme_selection.pack(fill=X, expand=YES)
lbl = ttk.Label(theme_selection, text="选择主题:")
theme_cbo = ttk.Combobox(master=theme_selection,text=style.theme.name,values=theme_names,)
theme_cbo.pack()
theme_cbo.current(theme_names.index(style.theme.name))
lbl.pack()
def change_theme(event):
theme_cbo_value = theme_cbo.get()
style.theme_use(theme_cbo_value)
theme_selected.configure(text=theme_cbo_value)
theme_cbo.selection_clear()
theme_cbo.bind('<<ComboboxSelected>>', change_theme)
theme_selected = ttk.Label( master=theme_selection,text="litera",font="-size 24 -weight bold")
theme_selected.pack()
root.mainloop()
效果图:
真的是一个一个字打的,不足之处请谅解。