14장. 메뉴, 파일열기
메뉴 작성
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# -*- coding:utf-8 -*- from tkinter import * from tkinter import messagebox def myFunc(): messagebox.showinfo("메뉴", "열기 메뉴 선택") window = Tk() mainMenu = Menu(window) window.configure(menu=mainMenu) fileMenu = Menu(mainMenu) mainMenu.add_cascade(label="파일", menu=fileMenu) fileMenu.add_command(label="열기", command = myFunc) fileMenu.add_separator() fileMenu.add_command(label="종료", command = quit) window.mainloop() |
파일 열기
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# -*- coding:utf-8 -*- from tkinter import * from tkinter import filedialog def file_open(): filename = filedialog.askopenfilename(parent=window, filetypes=(("GIF 파일", "*.gif"), ("모든 파일", "*.*"))) photo2 = PhotoImage(file=filename) pLabel.configure(image=photo2) pLabel.image = photo2 window = Tk() window.geometry("400x400") window.title("영화감상") photo = PhotoImage() pLabel = Label(window, image=photo) pLabel.pack(expand=1, anchor=CENTER) mainMenu = Menu(window) window.configure(menu=mainMenu) fileMenu = Menu(mainMenu) mainMenu.add_cascade(label="파일", menu=fileMenu) fileMenu.add_command(label="열기", command = file_open) fileMenu.add_separator() fileMenu.add_command(label="종료", command = quit) window.mainloop() |