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

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()#关闭数据库连接

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文件夹复制到c:\Python36-32\tcl\

将TkinterDnD2文件夹复制到C:\Python36-32\Lib\ (下载的是TkinterDnD2-0.2文件夹要复制的是里面的那个)

简单例子:

直接使用TkinterDnD2-0.2文件夹下的demo

快捷方式管理

故事的开头:公司妹子突然发彪说快捷方式全部消失.不高兴找原因了,然后找的软件被嫌弃太复杂,所以...自己写了一个功能简单的软件

喜欢的拿去随便用不过记得点赞.我会不定期的更新,需要增加功能的朋友请留言

# -*- 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)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值