barcode

경로때문에 개노가다 한 썰 푼다

Coding/Python

일단 개고생한 이유를 축약해드리자면... 

1. 윈도우에서는 폰트 저장 경로(C:\Windows\Fonts)에 있는 걸 갖다 쓰는 게 아니라 TTF, OTF파일이 있는 경로를 직접 입력해야 갖다 쓸 수 있음. 
2. 근데 리눅스는 폰트 저장 경로(/usr/share/fonts)에서 선택해서 쓸 수 있음. 

그래서 개고생했습니다. 


OS = platform.platform()
if 'Linux' in OS: 
    default_dir = '/home'
    root = tkinter.Tk()
    root.withdraw()
    font_dir = '/usr/share/fonts'
    font_path = filedialog.askopenfilename(parent=root, initialdir=font_dir, title='Choose your fonts for Wordcloud',
                                           filetypes=(("*.ttf", "*ttf"), ("*.otf", "*otf")))
elif 'Windows' in OS:
    default_dir = 'C:\\'
    root = tkinter.Tk()
    root.withdraw()
    font_path = filedialog.askopenfilename(parent=root, initialdir=default_dir, title='Choose your fonts for Wordcloud',
                                           filetypes=(("*.ttf", "*ttf"), ("*.otf", "*otf")))

그래서 코드도 이걸로 수정했음. 아예 OS에 따라 폰트 파일을 여는 방식이 다르기때문에 리눅스는 폰트가 저장된 경로를 띄우고, 윈도우는 알아서 파일 갖다 여시라고 친절하게 C드라이브 띄워드림.