PYTHON/tkinter
-
def save_file(txt): global current_file if current_file is not None: with open(current_file, 'w', encoding='utf-8') as f: f.write(txt.get("1.0", END)) else: #todo. 파일을 불러온 상태면! 그 파일을 덮어쓰기...내용을 추가하고 해당 파일을 다시 저장한다. #todo. 새로 작성하는 파일이면 이대로 저장할 파일명을 설정하고 저장하면 된다. #asksaveasfilename: SaveAs 다이올로그 생성 및 파일명 반환 file = filedialog.asksaveasfilename(..
tkinter - 메모장 (7) - 저장def save_file(txt): global current_file if current_file is not None: with open(current_file, 'w', encoding='utf-8') as f: f.write(txt.get("1.0", END)) else: #todo. 파일을 불러온 상태면! 그 파일을 덮어쓰기...내용을 추가하고 해당 파일을 다시 저장한다. #todo. 새로 작성하는 파일이면 이대로 저장할 파일명을 설정하고 저장하면 된다. #asksaveasfilename: SaveAs 다이올로그 생성 및 파일명 반환 file = filedialog.asksaveasfilename(..
2025.02.06 -
def open_file(window, txt): global current_file #askopenfile(s): Open 다이올로그 생성 및 파일 객체 반환 #askopenfilename(s): Open 다이올로그 생성 및 존재하는 파일 중 선택된 파일명 반환 file = filedialog.askopenfilename(title = "파일 열기", filetypes=(('텍스트 문서', '*.txt'), ('all files', '*.*'))) #todo파일을 불러왔으면 메모장 제목도 파일명으로 설정! -> 완료 filename = os.path.split(file) window.title(filename[1] + " - tkinter 메모장") if ..
tkinter - 메모장 (6) - 열기def open_file(window, txt): global current_file #askopenfile(s): Open 다이올로그 생성 및 파일 객체 반환 #askopenfilename(s): Open 다이올로그 생성 및 존재하는 파일 중 선택된 파일명 반환 file = filedialog.askopenfilename(title = "파일 열기", filetypes=(('텍스트 문서', '*.txt'), ('all files', '*.*'))) #todo파일을 불러왔으면 메모장 제목도 파일명으로 설정! -> 완료 filename = os.path.split(file) window.title(filename[1] + " - tkinter 메모장") if ..
2025.02.06 -
tkinter - 메모장 (4) - 새로 만들기 2025.02.06
-
def create_menu(window, txt): menu = Menu(window) menu_file = Menu(menu, tearoff=0) # todo. 단축키 -> 완료 # accelerator: 어떤 키를 바인딩할 것인지 표시하는 것. # lambda를 사용하지 않고 command: make_newone(window) 같은 형식으로 바로 함수가 실행되기 때문에 lambda를 사용한다. menu_file.add_command(label="새로 만들기", command=lambda: make_newone(), accelerator="Ctrl+N") menu_file.add_command(label="새 창", command=lambda: make_win..
tkinter - 메모장 (3) - 단축키def create_menu(window, txt): menu = Menu(window) menu_file = Menu(menu, tearoff=0) # todo. 단축키 -> 완료 # accelerator: 어떤 키를 바인딩할 것인지 표시하는 것. # lambda를 사용하지 않고 command: make_newone(window) 같은 형식으로 바로 함수가 실행되기 때문에 lambda를 사용한다. menu_file.add_command(label="새로 만들기", command=lambda: make_newone(), accelerator="Ctrl+N") menu_file.add_command(label="새 창", command=lambda: make_win..
2025.02.06 -
def create_menu(window, txt): menu = Menu(window) menu_file = Menu(menu, tearoff=0) # todo. 단축키 -> 완료 # accelerator: 어떤 키를 바인딩할 것인지 표시하는 것. # lambda를 사용하지 않고 command: make_newone(window) 같은 형식으로 바로 함수가 실행되기 때문에 lambda를 사용한다. menu_file.add_command(label="새로 만들기", command=lambda: make_newone(), accelerator="Ctrl+N") menu_file.add_command(label="새 창", command=lambda: make_win..
tkinter - 메모장 (2) - 메뉴def create_menu(window, txt): menu = Menu(window) menu_file = Menu(menu, tearoff=0) # todo. 단축키 -> 완료 # accelerator: 어떤 키를 바인딩할 것인지 표시하는 것. # lambda를 사용하지 않고 command: make_newone(window) 같은 형식으로 바로 함수가 실행되기 때문에 lambda를 사용한다. menu_file.add_command(label="새로 만들기", command=lambda: make_newone(), accelerator="Ctrl+N") menu_file.add_command(label="새 창", command=lambda: make_win..
2025.02.06 -
윈도우에 있는 Notepad를 흉내내보자from tkinter import *def main(): current_file = None window = Tk() window.title("제목 없음 - Windows 메모장") window.geometry("640x640+200+200") window.resizable(True, True) window.mainloop()if __name__ == "__main__": main()
tkinter - 메모장 (1) - 기본 윈도우 창윈도우에 있는 Notepad를 흉내내보자from tkinter import *def main(): current_file = None window = Tk() window.title("제목 없음 - Windows 메모장") window.geometry("640x640+200+200") window.resizable(True, True) window.mainloop()if __name__ == "__main__": main()
2025.02.06