python3.6.0-32 sqlite tkdnd tkinterdnd2 拖拽 快捷方式管理
admin
2023-07-24 03:42:22
0次

快捷方式管理(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 sqlite3
db = 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 win32api
import win32con
win32api.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 windnd

for idx,i in enumerate(ls):
    print(idx,i)

tk = Tk()
windnd.hook_dropfiles(tk,func = my_func
tk.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


快捷方式管理
故事的开头:公司妹子突然发彪说快捷方式全部消失.不高兴找原因了,然后找的软件被嫌弃太复杂,所以...自己写了一个功能简单的软件
喜欢的拿去随便用不过记得点赞.我会不定期的更新,需要增加功能的朋友请留言
python3.6.0-32 sqlite tkdnd tkinterdnd2 拖拽 快捷方式管理

# -*- coding: utf-8 -*-
#ver1.0 20180719
import platform
from TkinterDnD2 import *
from tkinter import *
import win32api
import win32con
import sqlite3
import os

def 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.action

db = 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()

数据库 db
CREATE TABLE lj(id integer primary key,lj text not NULL,isdel BOOLEAN DEFAULT 0)

相关内容

热门资讯

空调连续工作多久需要停机休息 空调连续工作的时间取决于多个因素,包括空调的型号、功率、使用环境和维护情况等。一般来说,空调可以连续...
空调哪个符号是除湿的 空调除湿功能通常用一个水滴形状的符号表示。不同品牌和型号的空调遥控器可能会有所差异,但一般来说,除湿...
格力空调多长时间加一次氟利昂 1、一般情况下,空调对氟利昂的使用量是非常小的,所以在空调使用了四年左右的时候再考虑加也没问题。2、...
空调用多长时间需要加氟一次 一般情况下是五年。当出现以下这几种情况时,空调才需要加氟。1、空调的室内机和室外机各有两个接口,当接...
格调生活·C标思享荟:卡萨帝在... 9月12日的郑州龙湖金融岛,夜风轻拂,灯光璀璨。“C标时刻共传奇——卡萨帝思享荟暨20周年品牌盛典郑...
品牌价值破千亿、高端份额持续领... 9月12日,“C标时刻共传奇——卡萨帝思享荟暨20周年品牌盛典郑州站”在郑州龙湖金融岛举办。2026...
空调主板坏了修800还是换新的 空调主板坏了是修还是换新,需要考虑多个因素,以下是一些建议:1. 维修成本:如果维修费用较低,比如 ...
空调开多久需要休息多长时间 问题:空调开多久需要休息多长时间回答:1、在使用空调的过程中,一般空调开7~8个小时左右需要休息2~...
中央空调多长时间清洗一次 1、一般空调开机前清洗一次即可,空调开机中间时段再清洗一次,空调关机时清洗一次,这样比较合理。2、空...
中央空调氟利昂多久加一次 看空调制热和制冷程度,很多人的观点认为氟利昂必须一年放一次,其实这个观点是错误的,理解上面有点偏差,...