溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

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

發(fā)布時間:2020-04-08 18:59:08 來源:網(wǎng)絡 閱讀:460 作者:ikezcn 欄目:編程語言

快捷方式管理(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") #在調(diào)用connect函數(shù)并指定庫名稱,如果不存在會按指定庫名稱自動創(chuàng)建.
cu = db.cursor()#游標
#cu.execute("create table lj(id integer primary key,lj text not NULL)") #執(zhí)行sql語句
#cu.execute("insert into lj(lj) values('c:\python27')")
db.commit()#事務提交
cu.execute("select * from lj;")#查詢
print cu.fetchall()#打印查詢結(jié)果,結(jié)果是{1 {c:\python27}}
cu.close()#關閉游標
db.close()#關閉數(shù)據(jù)庫連接

官方超詳細說明:https://docs.python.org/3.7/library/sqlite3.html


pywin32這個庫主要包含win32api和win32con
安裝:pip install pywin32
簡單例子:

import win32api
import win32con
win32api.MessageBox(win32con.NULL, '顯示內(nèi)容', '標題', 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:遇到問題,在使用滾動條的時候會發(fā)生錯誤,沒有繼續(xù)調(diào)試下去,換了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


快捷方式管理
故事的開頭:公司妹子突然發(fā)彪說快捷方式全部消失.不高興找原因了,然后找的軟件被嫌棄太復雜,所以...自己寫了一個功能簡單的軟件
喜歡的拿去隨便用不過記得點贊.我會不定期的更新,需要增加功能的朋友請留言
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, '數(shù)據(jù)整理錯誤',  '錯誤!', 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, '數(shù)據(jù)重復',  '錯誤!', 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, '新增-放入數(shù)據(jù)庫',  '錯誤!', 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='整理數(shù)據(jù)庫',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()

數(shù)據(jù)庫 db
CREATE TABLE lj(id integer primary key,lj text not NULL,isdel BOOLEAN DEFAULT 0)

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI