IT/Python

[Python] pywebview 응용 2개

잿호 2023. 9. 25. 22:48
01
- 실행 -

     


    시작하기 전

    1. pip install pywebview, pip install chess 를 꼭 해주셔야 합니다.

    2. webview.create_window("타이틀", "주소") #창 생성

    3. webview.start() #생성한 창 실행

     


    코드

     

    <1. 로아와 전적 검색>

    #로아와 전적검색
    import webview
    
    def open_naver(char_name):
        webview.create_window("loawa", f"https://loawa.com/char/{char_name}", width = 1000)
    
    if __name__ == "__main__":
        char_name = str(input("캐릭터 이름을 입력해주세요 : "))
        open_naver(char_name)
        webview.start()

     

    <2. 체스판 출력>

    #체스판 출력
    import webview
    import chess
    import chess.svg
    
    board = chess.Board()
    
    def generate_chess_board_svg():
        return chess.svg.board(board=board)
    
    def create_chess_window():
        webview.create_window(
            "Chess Game",
            html=f"<html><body>{generate_chess_board_svg()}</body></html>",
            width=400,
            height=400,
        )
    
    if __name__ == "__main__":
        create_chess_window()
        webview.start()

     


    실행

    012
    - 실행 -

     


    마무리

    코딩 공부중 pywebview를 찾아서 한번 가지고 놀아봤습니다. 웹크롤링에 잘 응용 가능 할 것 같습니다.

     

    반응형