PyQT5 컨트롤 크기 변경에 따른 윈도우 사이즈 변경, 바로 반영하기
예시 폴더를 불러오고, 컨트롤에 폴더 경로를 띄워줄 때 경로가 길다면 윈도우 크기가 그에 맞춰 가로로 길어진다. 하지만 같은 함수 안에서 호출되는 load_and_display_image에서는 image_viewer 사이즈에 맞춰 이미지를 출력하지만, 크기가 늘어나기 전 윈도우 사이즈에 맞춰 이미지가 출력된다. PyQT가 UI를 한번에 처리해서 문제 발생 update() repaint() 등등 해봤지만 해결되지 않았다. 해결 방법 from PyQt5.QtCore import QCoreApplication QCoreApplication.processEvents() # 이벤트 루프를 실행하여 UI 업데이트가 발생하도록 함 self.adjustSize() 문제되는 코드 def select_folder(self..
[pyinstaller] 명령어 , Anaconda 용량 줄이기 팁
Document: PyInstaller Manual — PyInstaller 6.0.0 documentation PyInstaller Manual — PyInstaller 6.0.0 documentation PyInstaller bundles a Python application and all its dependencies into a single package. The user can run the packaged app without installing a Python interpreter or any modules. PyInstaller supports Python 3.8 and newer, and correctly bundles many major P pyinstaller.org Quickstar..
[splitfolders] 이미지 폴더를 Train, Valid, Test로 나눠주는 라이브러리
import splitfolders dataset_path = 'D:\\Datasets\\kaggle\\Decks' output_path = dataset_path + '_splitted' print("dataset_path: ",dataset_path) print("output_path: ",output_path) print("splitfolders: start") splitfolders.ratio(dataset_path, output=output_path, seed=1337, ratio=(0.8, 0.2)) # Train / Valid #splitfolders.ratio(dataset_path, output=output_path, seed=1337, ratio=(0.8, 0.1, 0.1)) # Tra..
[파이썬] openpyxl 저장 오류
기능 openpyxl 의 wb.save() 가 오류나는 경우 시도해보자. 일반적으로 저장하려는 엑셀 파일이 열려있으면 오류가 생긴다. 구현 import win32com.client # openpyxl은 import 되어있다고 가정 try: wb.save(filename=fileName) except: excelFile = win32com.client.GetObject(fileDirectory) excelFile.Close(True) wb.save(filename=fileName)
[파이썬] openpyxl 셀 속성 변경 (테두리 지정, 가로 세로 맞춤)
기능 엑셀 셀 속성을 변경한다. 아래 구현 코드는 셀 좌상단 + 테두리를 지정해준다. align_gt = Alignment(horizontal='general', vertical='top',shrinkToFit=True) horizontal 변수 (셀 가로 속성) "general", "left", "center", "right", "fill", "justify", "centerContinuous", "distributed" vertical 변수 (셀 세로 속성) "top", "center", "bottom", "justify", "distributed", 구현 #엑셀 셀 속성 align_gt = Alignment(horizontal='general', vertical='top',shrinkToFit=Tr..
[파이썬] openpyxl 하이퍼링크 만들기
기능 openpyxl 패키지를 이용하여 엑셀에 하이퍼링크를 만들어준다. 셀 값이 폴더명일 때, 그 셀을 하이퍼링크로 만들어준다. 구현 user_path : 최상위 폴더 # 병합된 셀 구별 def parser_merged_cell(sheet: Worksheet, row, col): cell = sheet.cell(row=row, column=col) if isinstance(cell, MergedCell): # judge whether the cell is a merged cell for merged_range in ws.merged_cells.ranges: # loop to find the merge range to which the cell belongs if cell.coordinate in merg..
[파이썬] openpyxl 엑셀 세로로 같은 셀 병합
기능 2차원 리스트의 원소를 이용하여 세로로 같은 값을 가진 셀을 병합한다. 이 내용은 이전글인 [ 2022.04.22 - [집중 - 어제보다 나아가자/[개발] 파이썬 🍕] - [파이썬] openpyxl 엑셀에 2차원 리스트 원소 저장 ] 을 참고하자. 이전 글에서 2차원 리스트의 원소를 엑셀에 저장하고, 이 글에서는 세로로 같은 값을 가지는 셀을 병합한다. 구현 #엑셀 세로로 같은 내용이면 병합 for col in range(cols): str_cur = str_next = '' start_row = end_row = 0 for row in range(rows): try: #키 값이 존재하는지 확인 key = list_path_splited[row][col] #존재한다면 키값 받기 if row < ro..
[파이썬] openpyxl 엑셀 열 너비 자동 조절
기능 엑셀 열 너비를 자동 조절해주는 기능입니다. 구현 def set_column_length_auto(): for col in ws.columns: new_column_length = max(len(str(cell.value)) for cell in col) new_column_letter = (get_column_letter(col[0].column)) if new_column_length > 0: ws.column_dimensions[new_column_letter].width = new_column_length * 1.23 set_column_length_auto() fileName = 'test_column_length_auto.xlsx' wb.save(filename=fileName) 구현