|
楼主 |
发表于 2017-4-16 16:36:36
|
显示全部楼层
这个是现在的代码,大神们看看该如何处理,实现L21、L22、L23、L24、L25这五个Listbox的鼠标联动~~
- # -*- coding: utf-8 -*-
- from tkinter import *
- import os
- #设置工作路径
- path = "D:\\Sch_Pcb_Lib\\Pcb_Lib"
- os.chdir(path)
- items = os.listdir(path)#获取路径中所有文件列表
- dra_list = []#提取dra后缀文件
- for names in items:
- if names.endswith(".dra"):
- dra_list.append(names)
- len_dra_list = len(dra_list)#取列表长度
- psm_list = []#提取psm后缀文件
- for names in items:
- if names.endswith(".psm"):
- psm_list.append(names)
- len_psm_list = len(psm_list)#取列表长度
- txt_list = []#提取txt后缀文件
- for names in items:
- if names.endswith(".txt"):
- txt_list.append(names)
- len_txt_list = len(txt_list)#取列表长度
-
- log_list = []#提取log后缀文件
- for names in items:
- if names.endswith(".log"):
- log_list.append(names)
- len_log_list = len(log_list)#取列表长度
- del_list = []#提取log后缀文件
- for names in items:
- if names.endswith(",1"):
- del_list.append(names)
- if names.endswith(",2"):
- del_list.append(names)
- if names.endswith(".jrl"):
- del_list.append(names)
- len_del_list = len(del_list)#取列表长度
- def delList1(event):#双击事件
- index = L21.curselection()#返回当前选中项的索引
- os.remove(L21.get(index))#获取索引以及值
- L21.delete(L21.curselection())
- def delList2(event):#双击事件
- index = L22.curselection()#返回当前选中项的索引
- os.remove(L22.get(index))#获取索引以及值
- L22.delete(L22.curselection())
- def delList3(event):#双击事件
- index = L23.curselection()#返回当前选中项的索引
- os.remove(L23.get(index))#获取索引以及值
- L23.delete(L23.curselection())
- def delList4(event):#双击事件
- index = L24.curselection()#返回当前选中项的索引
- os.remove(L24.get(index))#获取索引以及值
- L24.delete(L24.curselection())
- def delList5(event):#双击事件
- index = L25.curselection()#返回当前选中项的索引
- os.remove(L25.get(index))#获取索引以及值
- L25.delete(L25.curselection())
- root = Tk()
- root.title('封装管理')
- root.attributes('-alpha',0.8)
- root.resizable(width=False, height=False)
- L11 = Label(root, bg = '#F0F0F0', fg = "red", width = 20,font = ('微软雅黑', '10'), text = 'Dra',anchor="w", )
- L11.grid(row = 0, column = 0, padx = 1, pady = 1)
- L12 = Label(root, bg = '#F0F0F0', fg = "red", width = 20,font = ('微软雅黑', '10'), text = 'Psm',anchor="w", )
- L12.grid(row = 0, column = 1, padx = 1, pady = 1)
- L13 = Label(root, bg = '#F0F0F0', fg = "red", width = 20,font = ('微软雅黑', '10'), text = 'Txt',anchor="w", )
- L13.grid(row = 0, column = 2, padx = 1, pady = 1)
- L14 = Label(root, bg = '#F0F0F0', fg = "red", width = 20,font = ('微软雅黑', '10'), text = 'Log',anchor="w", )
- L14.grid(row = 0, column = 3, padx = 1, pady = 1)
- L15 = Label(root, bg = '#F0F0F0', fg = "red", width = 20,font = ('微软雅黑', '10'), text = 'Del',anchor="w", )
- L15.grid(row = 0, column = 4, padx = 1, pady = 1)
- L21 = Listbox(root, bg = '#F0F0F0',\
- width = 20,\
- font = ('微软雅黑', '10'),
- borderwidth = 0,\
- )
- for item in dra_list: # 第一个小部件插入数据
- L21.insert(0,item)
- L21.grid(row = 1, column = 0, padx = 1, pady = 1)
- #L21.bind('<Double-Button-1>', delList1)
- L22 = Listbox(root, bg = '#F0F0F0',\
- width = 20,\
- font = ('微软雅黑', '10'),
- borderwidth = 0,\
- )
- for item in psm_list: # 第二个小部件插入数据
- L22.insert(0,item)
- L22.grid(row = 1, column = 1, padx = 1, pady = 1)
- #L22.bind('<Double-Button-1>', delList2)
- L23 = Listbox(root, bg = '#F0F0F0',\
- width = 20,\
- font = ('微软雅黑', '10'),
- borderwidth = 0,\
- )
- for item in txt_list: # 第三个小部件插入数据
- L23.insert(0,item)
- L23.grid(row = 1, column = 2, padx = 1, pady = 1)
- #L23.bind('<Double-Button-1>', delList3)
- L24 = Listbox(root, bg = '#F0F0F0',\
- width = 20,\
- font = ('微软雅黑', '10'),
- borderwidth = 0,\
- )
- for item in log_list: # 第四个小部件插入数据
- L24.insert(0,item)
- L24.grid(row = 1, column = 3, padx = 1, pady = 1)
- #L24.bind('<Double-Button-1>', delList4)
- L25 = Listbox(root, bg = '#F0F0F0',\
- width = 20,\
- font = ('微软雅黑', '10'),
- borderwidth = 0,\
- )
- for item in del_list: # 第五个小部件插入数据
- L25.insert(0,item)
- L25.grid(row = 1, column = 4, padx = 1, pady = 1)
- L25.bind('<Double-Button-1>', delList5)
- v1 = StringVar()
- v1.set(len_dra_list)
- L31 = Label(root, bg = '#F0F0F0', fg = "red", width = 20,font = ('微软雅黑', '10'), anchor="w", textvariable = v1)
- L31.grid(row = 2, column = 0, padx = 1, pady = 1)
- v2 = StringVar()
- v2.set(len_psm_list)
- L32 = Label(root, bg = '#F0F0F0', fg = "red", width = 20,font = ('微软雅黑', '10'), anchor="w", textvariable = v2)
- L32.grid(row = 2, column = 1, padx = 1, pady = 1)
- v3 = StringVar()
- v3.set(len_txt_list)
- L33 = Label(root, bg = '#F0F0F0', fg = "red", width = 20,font = ('微软雅黑', '10'), anchor="w", textvariable = v3)
- L33.grid(row = 2, column = 2, padx = 1, pady = 1)
- v4 = StringVar()
- v4.set(len_log_list)
- L34 = Label(root, bg = '#F0F0F0', fg = "red", width = 20,font = ('微软雅黑', '10'), anchor="w", textvariable = v4)
- L34.grid(row = 2, column = 3, padx = 1, pady = 1)
- v5 = StringVar()
- v5.set(len_del_list)
- L35 = Label(root, bg = '#F0F0F0', fg = "red", width = 20,font = ('微软雅黑', '10'), anchor="w", textvariable = v5)
- L35.grid(row = 2, column = 4, padx = 1, pady = 1)
- mainloop()
复制代码 |
|