python3.6.0-32 sqlite tkdnd tkinterdnd2 拖拽 快捷方式管理

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 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('<Double-Button-1>',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>>', 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)

转载于:https://blog.51cto.com/ikezcn/2142638

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/101547.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • JDBC解析7_Blob

    JDBC解析7_Blob

    2021年8月8日
    66
  • 2008秋-计算机软件基础-多关键字排序

    2008秋-计算机软件基础-多关键字排序

    2021年7月28日
    72
  • 页面ValidateRequest=false设置在asp.net4.0下失效

    页面ValidateRequest=false设置在asp.net4.0下失效
    ASP.NET请求验证功能可以给我提供应用程序的安全保证,避免站点受到XSS的攻击。但是在一些情况下,我们需要禁用这个功能,比如我们需要使用HtmlEditor来让用户输入一些HTML文本,这时候ASP.NET2.0允许我们可以通过在web.config设置validateRequest=”false”。或者在MVC中,我们可以通过在Controller或者Action上设置[ValidateRequest(false)]这个特性来达到禁用的上的。但是在当你把站点从旧版本升级到ASP.NET

    2022年5月23日
    35
  • CSDN更换博客皮肤教程

    CSDN更换博客皮肤教程1.进入博客设置,按F12键打开开发者工具调试页面2.找到博客皮肤的div,鼠标右键编辑HTML3.将checked=“checked”readonly=””剪切到你想要的皮肤里面,这里我是技术黑板的皮肤,之前就改了4.点击左边的页面,可以看到想要的皮肤是选中状态,然后点击保存,皮肤更改成功!…

    2022年7月14日
    18
  • linux 查看java的pid,linux 查看java进程pid「建议收藏」

    linux 查看java的pid,linux 查看java进程pid「建议收藏」linux查看java进程pid[2021-01-3021:05:24]简介:建站服务器这篇文章主要介绍了linux中如何查看系统进程,具有一定借鉴价值,需要的朋友可以参考下。希望大家阅读完这篇文章后大有收获。下linux查看端口被哪个进程占用的方法:1、使用“lsof-i:端口号”来查看;2、使用“netstat-tunlp|grep端口号”来查看。linux查看端口被哪个进程占…

    2022年8月24日
    9
  • HDU 1541 Stars (树状数组)

    HDU 1541 Stars (树状数组)

    2022年1月10日
    36

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号