python3.6.0-32 sqlite tkdnd tkinterdnd2 拖拽 快捷方式管理
快捷方式管理(pyqt5升级版,不在对这篇更新)https://blog.51cto.com/ikezcn/2166426
连接sqlite3
python软件:https://www.python.org/ftp/python/3.6.0/python-3.6.0.exe
pytho自带sqlite3,所以只需要import
简单例子:
import sqlite3db = sqlite3.connect("./db") #在调用connect函数并指定库名称,如果不存在会按指定库名称自动创建.cu = db.cursor()#游标#cu.execute("create table lj(id integer primary key,lj text not NULL)") #执行sql语句#cu.execute("insert into lj(lj) values('c:\python27')")db.commit()#事务提交cu.execute("select * from lj;")#查询print cu.fetchall()#打印查询结果,结果是{1 {c:\python27}}cu.close()#关闭游标db.close()#关闭数据库连接
官方超详细说明:https://docs.python.org/3.7/library/sqlite3.html
pywin32这个库主要包含win32api和win32con
安装:pip install pywin32
简单例子:
import win32apiimport win32conwin32api.MessageBox(win32con.NULL, '显示内容', '标题', win32con.MB_OK)win32api.ShellExecute(0,'open',r'D:\1.txt','','',1)#不会像os.system弹出黑框
windnd对 windows 桌面图标拖拽加载路径
安装:pip install windnd
简单例子:
from tkinter import *import windndfor idx,i in enumerate(ls): print(idx,i)tk = Tk()windnd.hook_dropfiles(tk,func = my_functk.mainloop()
ps:遇到问题,在使用滚动条的时候会发生错误,没有继续调试下去,换了tkdnd
tkdnd2.8 tkinterDnD2
软件:
tkdnd2.8 https://sourceforge.net/projects/tkdnd/
TkinterDnD2 http://sourceforge.net/projects/tkinterdnd/files/
安装:
将tkdnd2.8文件夹复制到c:\Python36-32\tcl\
将TkinterDnD2文件夹复制到C:\Python36-32\Lib\ (下载的是TkinterDnD2-0.2文件夹要复制的是里面的那个)
简单例子:
直接使用TkinterDnD2-0.2文件夹下的demo
快捷方式管理
故事的开头:公司妹子突然发彪说快捷方式全部消失.不高兴找原因了,然后找的软件被嫌弃太复杂,所以...自己写了一个功能简单的软件
喜欢的拿去随便用不过记得点赞.我会不定期的更新,需要增加功能的朋友请留言
# -*- coding: utf-8 -*-#ver1.0 20180719import platformfrom TkinterDnD2 import *from tkinter import *import win32apiimport win32conimport sqlite3import osdef delCallBack(): if listbox.curselection() == (): return cu.execute("update lj set isdel = 1 where lj=?",(listbox.get(listbox.curselection()),)) if db.commit() == None: listbox.delete(listbox.curselection()) else: win32api.MessageBox(win32con.NULL, '删除时错误', '错误!', win32con.MB_OK)def alldelCallBack(): cu.execute('update lj set isdel = 1') if db.commit() == None: listbox.delete(0,'end') else: win32api.MessageBox(win32con.NULL, '全部删除时错误', '错误!', win32con.MB_OK)def flushCallBack(): listbox.delete(0,END) tables = cu.execute("select * from lj where isdel = 0 order by lj") for table in tables.fetchall(): listbox.insert('end',table[1])def printList(event): if os.path.exists(listbox.get(listbox.curselection())): win32api.ShellExecute(0,'open',listbox.get(listbox.curselection()),'','',1) else: win32api.MessageBox(win32con.NULL, '打开错误', '错误!', win32con.MB_OK)def vacuumCallBack(): cu.execute('delete from lj where isdel = 1') if db.commit() == None: cu.execute('VACUUM') else: win32api.MessageBox(win32con.NULL, '数据整理错误', '错误!', win32con.MB_OK)def drop(event): if event.data: files = listbox.tk.splitlist(event.data) for f in files: if os.path.exists(f): tables = cu.execute("select 1 from lj where lj=? and isdel = 0 limit 1",(os.path.abspath(f),)) for table in tables.fetchall(): if table[0] == 1: win32api.MessageBox(win32con.NULL, '数据重复', '错误!', win32con.MB_OK) return cu.execute("insert into lj(lj) values(?)",(os.path.abspath(f),)) if db.commit() == None: listbox.insert('end',os.path.abspath(f)) else: win32api.MessageBox(win32con.NULL, '新增-放入数据库', '错误!', win32con.MB_OK) else: win32api.MessageBox(win32con.NULL, '新增-文件不存在', '错误!', win32con.MB_OK) return event.actiondb = sqlite3.connect("./db")cu = db.cursor()tables = cu.execute("SELECT COUNT(*) FROM sqlite_master where type ='table' and name =?",('lj',))for table in tables.fetchall(): if table[0] == 0: cu.execute("create table lj(id integer primary key,lj text not NULL,isdel BOOLEAN DEFAULT 0)") cu.execute("create index lj_index on lj(lj)") cu.execute("create index isdel_index on lj(isdel)") db.commit()root = TkinterDnD.Tk()root.withdraw()root.title('快捷方式管理')root.grid_rowconfigure(1, weight=1, minsize=800)root.grid_columnconfigure(0, weight=1, minsize=800)scrollbar = Scrollbar(root)scrollbar.grid(row=1,column=1,sticky='ns')listbox = Listbox(root, name='listbox',selectmode='extended',yscrollcommand = scrollbar.set, width=1, height=1)listbox.bind('',printList)listbox.grid(row=1, column=0, padx=5, pady=5, sticky='news')scrollbar.config(command = listbox.yview)tables = cu.execute("select * from lj where isdel = 0 order by lj")for table in tables.fetchall(): listbox.insert('end',table[1])menubar = Menu(root)menubar1 = Menu(root)menubar1.add_command(label='全部删除',command=alldelCallBack)menubar1.add_command(label='整理数据库',command=vacuumCallBack)menubar.add_command(label="删除",command=delCallBack)menubar.add_cascade(label="设置",menu=menubar1)menubar.add_command(label="刷新",command=flushCallBack)listbox.drop_target_register(DND_FILES)listbox.dnd_bind('<>', drop)root.config(menu=menubar)root.update_idletasks()root.deiconify()root.mainloop()
数据库 dbCREATE TABLE lj(id integer primary key,lj text not NULL,isdel BOOLEAN DEFAULT 0)