반응형

pyperclip 1.8.2

 

>> pip install pyperclip

 

 

A cross-platform clipboard module for Python. (Only handles plain text for now.)

 

https://pypi.org/project/pyperclip/

 

pyperclip

A cross-platform clipboard module for Python. (Only handles plain text for now.)

pypi.org

>>> import pyperclip
>>> pyperclip.copy('The text to be copied to the clipboard.')
>>> pyperclip.paste()
'The text to be copied to the clipboard.'

 

반응형
반응형

크로스 플랫폼 사용자 인터페이스의 신속한 개발을 위한 오픈 소스 파이썬 라이브러리다.

키비 응용 프로그램을 사용하면 리눅스, 윈도우에 사용하는 GUI 프로그램뿐 아니라 안드로이드, IOS 용도로 개발할 수 있다.

 

https://kivy.org/

 

Kivy: Cross-platform Python Framework for NUI

Open source Python framework for rapid development of applications that make use of innovative user interfaces, such as multi-touch apps.

kivy.org

https://kivy.org/doc/stable/gettingstarted/intro.html

 

Introduction — Kivy 2.2.1 documentation

Introduction Start Developing Kivy Apps Right Away! Creating Kivy apps is fun and rewarding. This guide should be the perfect starting point to get you on the right track for app development. You will require a basic knowledge of Python to follow this intr

kivy.org

https://wikidocs.net/book/8263

 

kivy 한글 공식페이지

문의: mr.everything.kr@gmail.com

wikidocs.net

# pip install kivy


from kivy.app import App
from kivy.uix.button import Button

class YourApp(App):
    def build(self):
        return Button(text="Hello, Kivy!")

if __name__ == '__main__':
    YourApp().run()
반응형
반응형

PyMuPDF is a high performance Python library for data extraction, analysis, conversion & manipulation of PDF (and other) documents.

https://pypi.org/project/PyMuPDF/

>> pip install PyMuPDF

 

https://mupdf.com/

 

1.디렉토리 안의 pdf 파일을 읽어들여서 리스트 목록을 출력

2.파일명을 넘기면 파일명_이미지순서.png 파일을 생성. 

import fitz  # PyMuPDF

 
# 파이썬 컴파일 경로가 달라서 현재 폴더의 이미지를 호출하지 못할때 작업디렉토리를 변경한다. 
import os
from pathlib import Path
# src 상위 폴더를 실행폴더로 지정하려고 한다.
###real_path = Path(__file__).parent.parent
real_path = Path(__file__).parent
print(real_path)
#작업 디렉토리 변경
os.chdir(real_path) 

directory_base = str(real_path)+"./ONE/"  # 경로object를 문자열로 변경해서 합친다. 
 


def pdf_to_png(pdf_file, input_pdf_name, output_folder):
    # Open the PDF file
    pdf_document = fitz.open(pdf_file)
    
    for page_number in range(pdf_document.page_count):
        # Get the page
        page = pdf_document[page_number]
        
        # Convert the page to an image
        image = page.get_pixmap()
        
        # Save the image as a PNG file
        image.save(f"{output_folder}/{input_pdf_name}_{page_number + 1}.png", "png")

    # Close the PDF file
    pdf_document.close()

if __name__ == "__main__":
     
    # List all files in the directory
    file_list = [f for f in os.listdir(directory_base) if os.path.isfile(os.path.join(directory_base, f))]

    # Print the list of files
    for file in file_list:
        print(file)
        
        #input_pdf = "./TWO/"+ file_name +".pdf"  # Replace with your PDF file path
        input_pdf      = "./ONE/"+ file  # Replace with your PDF file path
        input_pdf_name = os.path.splitext(file)[0]
        print(input_pdf_name)
        output_folder  = "./ONE/data"  # Replace with your output folder
        
        pdf_to_png(input_pdf, input_pdf_name, output_folder)

 

반응형

'프로그래밍 > Python' 카테고리의 다른 글

[python] pyperclip  (0) 2023.09.18
[Python] kivy  (0) 2023.09.15
[python] PyMuPDF로 코딩 없이 PDF에서 이미지 추출  (0) 2023.09.14
[python] cowsay  (0) 2023.09.14
[PYTHON] Python tkinter 강좌  (0) 2023.08.25
반응형

PyMuPDF로 코딩 없이 PDF에서 이미지 추출

 

https://wikidocs.net/181972

 

PyMuPDF로 코딩 없이 PDF에서 이미지 추출

[PyMuPDF](https://github.com/pymupdf/PyMuPDF)의 fitz를 이용해 PDF 파일에서 이미지를 추출할 수 있다. [명령행 모듈](https://p…

wikidocs.net

# PyMuPDF로 코딩 없이 PDF에서 이미지 추출


# PyMuPDF


# pip install PyMuPDF



import fitz
doc = fitz.open(PDF_FILE_PATH)
for i, page in enumerate(doc):
    img = page.get_pixmap()
    img.save(f"./data/{i}.png")



# Command 로 바로 실행하기 
# python -m fitz extract -images input.pdf
반응형

'프로그래밍 > Python' 카테고리의 다른 글

[Python] kivy  (0) 2023.09.15
[python] PDF to png, import fitz , PyMuPDF  (0) 2023.09.15
[python] cowsay  (0) 2023.09.14
[PYTHON] Python tkinter 강좌  (0) 2023.08.25
[python] chatGPT에게 TicTacToe 만들어달라고 했다.  (0) 2023.08.21
반응형
""" cowsay 
    https://pypi.org/project/cowsay/
    
    pip install cowsay
"""

import cowsay 

cowsay.cow(" hellow, Cow")

cowsay.daemon("Hi demon")

반응형
반응형

https://076923.github.io/posts/Python-tkinter-1/

 

Python tkinter 강좌 : 제 1강 - GUI 생성

tkinter

076923.github.io

""" Python tkinter 강좌  : https://076923.github.io/posts/Python-tkinter-2/

    Label, Button, Entry, ListBox, CheckButton 
"""
import tkinter

window=tkinter.Tk()
window.title("KIM HONG WAN")
window.geometry("640x400+100+100")
window.resizable(False, True) # 좌우, 상하

label0=tkinter.Label(window, text="파이썬", width=10, height=5, fg="red", relief="solid")
label0.pack()


count = 0

def countUP():
    global count
    count +=1
    label.config(text=str(count))

# Label을 이용하여 삽입한 이미지나 도표, 그림 등에 사용되는 주석문을 생성할 수 있습니다.
label = tkinter.Label(window, text="0")
label.pack()

# Button을 이용하여 메서드 또는 함수 등을 실행시키기 위한 단추를 생성할 수 있습니다.
button = tkinter.Button(window, overrelief="solid", width=15, command=countUP, repeatdelay=1000, repeatinterval=100)
button.pack()


label2 = tkinter.Label(window, text="0")
label2.pack()

def calc(event):
    label2.config(text="결과="+str(eval(entry.get())))

# Entry을 이용하여 텍스트를 입력받거나 출력하기 위한 기입창을 생성할 수 있습니다
entry=tkinter.Entry(window)
entry.bind("<Return>", calc)
entry.pack()


# Listbox을 이용하여 목록을 불러와 추가, 제거 또는 선택하기 위한 리스트박스를 생성할 수 있습니다
listbox = tkinter.Listbox(window, selectmode='extended', height=0)
listbox.insert(0, "1번")
listbox.insert(1, "2번")
listbox.insert(2, "2번")
listbox.insert(3, "2번")
listbox.insert(4, "3번")

listbox.delete(1, 2)

listbox.insert(1, "1-1번")

listbox.pack()

# Checkbutton을 이용하여 옵션 등을 다중 선택하기 위한 체크버튼을 생성할 수 있습니다.
def flash():
    checkbutton1.flash()

CheckVariety_1=tkinter.IntVar()
CheckVariety_2=tkinter.IntVar()

checkbutton1=tkinter.Checkbutton(window, text="O", variable=CheckVariety_1, activebackground="blue")
checkbutton2=tkinter.Checkbutton(window, text="△", variable=CheckVariety_2)
checkbutton3=tkinter.Checkbutton(window, text="X", variable=CheckVariety_2, command=flash)

checkbutton1.pack()
checkbutton2.pack()
checkbutton3.pack()


# Radiobutton을 이용하여 옵션 등을 단일 선택하기 위한 라디오버튼을 생성할 수 있습니다.
def check():
    label.config(text= "RadioVariety_1 = " + str(RadioVariety_1.get()) + "\n" +
                       "RadioVariety_2 = " + str(RadioVariety_2.get()) + "\n\n" +
                       "Total = "          + str(RadioVariety_1.get() + RadioVariety_2.get()))

RadioVariety_1=tkinter.IntVar()
RadioVariety_2=tkinter.IntVar()

radio1=tkinter.Radiobutton(window, text="1번", value=3, variable=RadioVariety_1, command=check)
radio1.pack()

radio2=tkinter.Radiobutton(window, text="2번(1번)", value=3, variable=RadioVariety_1, command=check)
radio2.pack()

radio3=tkinter.Radiobutton(window, text="3번", value=9, variable=RadioVariety_1, command=check)
radio3.pack()

label=tkinter.Label(window, text="None", height=5)
label.pack()

radio4=tkinter.Radiobutton(window, text="4번", value=12, variable=RadioVariety_2, command=check)
radio4.pack()

radio5=tkinter.Radiobutton(window, text="5번", value=15, variable=RadioVariety_2, command=check)
radio5.pack()


# Menu을 이용하여 자주 사용하는 기능 등을 다양한 선택사항으로 나누는 메뉴을 생성할 수 있습니다.
def close():
    window.quit()
    window.destroy()

menubar=tkinter.Menu(window)

menu_1=tkinter.Menu(menubar, tearoff=0)
menu_1.add_command(label="하위 메뉴 1-1")
menu_1.add_command(label="하위 메뉴 1-2")
menu_1.add_separator()
menu_1.add_command(label="하위 메뉴 1-3", command=close)
menubar.add_cascade(label="상위 메뉴 1", menu=menu_1)

menu_2=tkinter.Menu(menubar, tearoff=0, selectcolor="red")
menu_2.add_radiobutton(label="하위 메뉴 2-1", state="disable")
menu_2.add_radiobutton(label="하위 메뉴 2-2")
menu_2.add_radiobutton(label="하위 메뉴 2-3")
menubar.add_cascade(label="상위 메뉴 2", menu=menu_2)

menu_3=tkinter.Menu(menubar, tearoff=0)
menu_3.add_checkbutton(label="하위 메뉴 3-1")
menu_3.add_checkbutton(label="하위 메뉴 3-2")
menubar.add_cascade(label="상위 메뉴 3", menu=menu_3)

window.config(menu=menubar)


window.mainloop()



print("Window Close")
반응형
반응형

[python] chatGPT에게 TicTacToe 만들어달라고 했다. 

import tkinter as tk
from tkinter import messagebox

class TicTacToe:
    def __init__(self, root):
        self.root = root
        self.root.title("Tic-Tac-Toe")

        self.current_player = "X"
        self.board = [""] * 9

        self.buttons = []
        for i in range(9):
            button = tk.Button(root, text="", width=10, height=3, command=lambda i=i: self.make_move(i))
            button.grid(row=i // 3, column=i % 3)
            self.buttons.append(button)

    def make_move(self, position):
        if not self.board[position]:
            self.board[position] = self.current_player
            self.buttons[position].config(text=self.current_player)
            
            if self.check_winner():
                messagebox.showinfo("Game Over", f"Player {self.current_player} wins!")
                self.reset_game()
            elif all(cell != "" for cell in self.board):
                messagebox.showinfo("Game Over", "It's a draw!")
                self.reset_game()
            else:
                self.current_player = "O" if self.current_player == "X" else "X"

    def check_winner(self):
        winning_combinations = [(0, 1, 2), (3, 4, 5), (6, 7, 8),
                                (0, 3, 6), (1, 4, 7), (2, 5, 8),
                                (0, 4, 8), (2, 4, 6)]

        for combo in winning_combinations:
            if self.board[combo[0]] == self.board[combo[1]] == self.board[combo[2]] != "":
                return True
        return False

    def reset_game(self):
        self.current_player = "X"
        self.board = [""] * 9
        for button in self.buttons:
            button.config(text="")

if __name__ == "__main__":
    root = tk.Tk()
    game = TicTacToe(root)
    root.mainloop()
반응형
반응형

https://pypi.org/project/secure-smtplib/

 

secure-smtplib

Secure SMTP subclasses for Python 2

pypi.org

secure-smtplib 0.1.1

 

pip install secure-smtplib

 

 

.chatGPT에게 " python email sending app " 이라고 질문했다. 

# chatGPT - python email sending app 
import tkinter as tk
from tkinter import messagebox
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

def send_email():
    sender_email = sender_email_entry.get()
    sender_password = sender_password_entry.get()
    recipient_email = recipient_email_entry.get()
    subject = subject_entry.get()
    message = message_text.get("1.0", tk.END)
    
    try:
        # Set up the SMTP server
        smtp_server = smtplib.SMTP("smtp.gmail.com", 587)
        smtp_server.starttls()
        smtp_server.login(sender_email, sender_password)
        
        # Create the email
        email = MIMEMultipart()
        email["From"] = sender_email
        email["To"] = recipient_email
        email["Subject"] = subject
        email.attach(MIMEText(message, "plain"))
        
        # Send the email
        smtp_server.sendmail(sender_email, recipient_email, email.as_string())
        smtp_server.quit()
        
        messagebox.showinfo("Success", "Email sent successfully!")
    except Exception as e:
        messagebox.showerror("Error", f"An error occurred: {str(e)}")

# Create the main GUI window
root = tk.Tk()
root.title("Email Sending App")

# Create and place widgets
sender_email_label = tk.Label(root, text="Sender Email:")
sender_email_label.pack()

sender_email_entry = tk.Entry(root)
sender_email_entry.pack()

sender_password_label = tk.Label(root, text="Sender Password:")
sender_password_label.pack()

sender_password_entry = tk.Entry(root, show="*")
sender_password_entry.pack()

recipient_email_label = tk.Label(root, text="Recipient Email:")
recipient_email_label.pack()

recipient_email_entry = tk.Entry(root)
recipient_email_entry.pack()

subject_label = tk.Label(root, text="Subject:")
subject_label.pack()

subject_entry = tk.Entry(root)
subject_entry.pack()

message_label = tk.Label(root, text="Message:")
message_label.pack()

message_text = tk.Text(root, height=10, width=40)
message_text.pack()

send_button = tk.Button(root, text="Send Email", command=send_email)
send_button.pack()

root.mainloop()
반응형

+ Recent posts