add drop down
This commit is contained in:
BIN
__pycache__/reading_sheet.cpython-313.pyc
Normal file
BIN
__pycache__/reading_sheet.cpython-313.pyc
Normal file
Binary file not shown.
20
main.py
20
main.py
@@ -2,6 +2,8 @@ import tkinter as tk
|
|||||||
from tkinter import filedialog
|
from tkinter import filedialog
|
||||||
import algam
|
import algam
|
||||||
import save
|
import save
|
||||||
|
from reading_sheet import ReadingSheet
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#def Pars():
|
#def Pars():
|
||||||
@@ -14,7 +16,7 @@ import save
|
|||||||
def Pars():
|
def Pars():
|
||||||
data = algam.ReadMifDirectory().find_mif_files(directory=directory_entry.get())
|
data = algam.ReadMifDirectory().find_mif_files(directory=directory_entry.get())
|
||||||
|
|
||||||
save.SaveDataXLSX(file_path=file_to_save_entry.get(),sheet_name="Лист1",data=data)
|
save.SaveDataXLSX(file_path=file_to_save_entry.get(),sheet_name=drop_var_two.get(),data=data)
|
||||||
|
|
||||||
root = tk.Tk()
|
root = tk.Tk()
|
||||||
root.title("Parser11(отяет по mif)")
|
root.title("Parser11(отяет по mif)")
|
||||||
@@ -34,6 +36,18 @@ def open_excel_file(event, entry):
|
|||||||
entry.delete(0, tk.END)
|
entry.delete(0, tk.END)
|
||||||
entry.insert(0, excel_path)
|
entry.insert(0, excel_path)
|
||||||
|
|
||||||
|
options.clear()
|
||||||
|
readingSheets = ReadingSheet(path=excel_path)
|
||||||
|
sheets = readingSheets.Read()
|
||||||
|
for _sheet in sheets:
|
||||||
|
options.append(_sheet)
|
||||||
|
|
||||||
|
drop_var_two.set(options[0])
|
||||||
|
menu = dropdown_two["menu"]
|
||||||
|
menu.delete(0,"end")
|
||||||
|
for option in options:
|
||||||
|
menu.add_command(label=option, command=tk._setit(drop_var_two,option))
|
||||||
|
|
||||||
# первое поле с списком
|
# первое поле с списком
|
||||||
file_to_save_label = tk.Label(root, text="файл_для_сохранения", font=font)
|
file_to_save_label = tk.Label(root, text="файл_для_сохранения", font=font)
|
||||||
file_to_save_label.pack(anchor="w")
|
file_to_save_label.pack(anchor="w")
|
||||||
@@ -41,6 +55,10 @@ file_to_save_entry = tk.Entry(root, font=font, width=70)
|
|||||||
file_to_save_entry.pack(anchor="w")
|
file_to_save_entry.pack(anchor="w")
|
||||||
file_to_save_entry.bind("<Button-1>", lambda event: open_excel_file(event, file_to_save_entry))
|
file_to_save_entry.bind("<Button-1>", lambda event: open_excel_file(event, file_to_save_entry))
|
||||||
|
|
||||||
|
drop_var_two=tk.StringVar()
|
||||||
|
dropdown_two = tk.OptionMenu(root, drop_var_two, *options)
|
||||||
|
dropdown_two.pack(anchor="w")
|
||||||
|
|
||||||
directory_label = tk.Label(root, text="Выберите директорию c mif:", font=font)
|
directory_label = tk.Label(root, text="Выберите директорию c mif:", font=font)
|
||||||
directory_label.pack(anchor="w")
|
directory_label.pack(anchor="w")
|
||||||
directory_entry = tk.Entry(root, font=font, width=70)
|
directory_entry = tk.Entry(root, font=font, width=70)
|
||||||
|
|||||||
17
reading_sheet.py
Normal file
17
reading_sheet.py
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import openpyxl
|
||||||
|
|
||||||
|
class ReadingSheet():
|
||||||
|
"""
|
||||||
|
класс для чтения листов в книгах
|
||||||
|
path - путь к файлу
|
||||||
|
"""
|
||||||
|
def __init__(self, path):
|
||||||
|
self.path = path
|
||||||
|
"""path - путь к файлу"""
|
||||||
|
|
||||||
|
def Read(self):
|
||||||
|
"""прочитать и вернуть все листы в виде массива названия листов"""
|
||||||
|
workbook = openpyxl.load_workbook(self.path)
|
||||||
|
sheets = workbook.sheetnames
|
||||||
|
workbook.close()
|
||||||
|
return sheets
|
||||||
2
save.py
2
save.py
@@ -4,7 +4,7 @@ class SaveDataXLSX():
|
|||||||
def __init__(self,file_path:str,sheet_name:str,data):
|
def __init__(self,file_path:str,sheet_name:str,data):
|
||||||
wb = xl.load_workbook(filename=file_path)
|
wb = xl.load_workbook(filename=file_path)
|
||||||
sheet = wb[sheet_name]
|
sheet = wb[sheet_name]
|
||||||
max_row = sheet.max_row+2
|
max_row = sheet.max_row+1
|
||||||
for new_row,file in enumerate(data):
|
for new_row,file in enumerate(data):
|
||||||
sheet.cell(row=max_row+new_row,column=2,value=file.directory)
|
sheet.cell(row=max_row+new_row,column=2,value=file.directory)
|
||||||
sheet.cell(row=max_row+new_row,column=3,value=file.cad_number)
|
sheet.cell(row=max_row+new_row,column=3,value=file.cad_number)
|
||||||
|
|||||||
Reference in New Issue
Block a user