Nim : 1610131310013
Tugas 7
window=Tk()
window.title("Menu")
window.geometry("350x200")
def hello():
lbl.configure(text="hello")
lbl =Label(window,text="aa")
lbl.grid(column=0, row=0)
menu=Menu(window)
item=Menu(menu)
item2=Menu(menu)
item.add_command(label="Hello", command=hello)
item.add_command(label="Open Text File")
item.add_command(label="Open Image File")
item.add_command(label="Exit", command=window.quit)
menu.add_cascade(label="file", menu=item)
item2.add_command(label="hello")
item2.add_command(label="would")
menu.add_cascade(label="Edit", menu=item2)
window.config(menu=menu)
window.mainloop()
Hasilnya
from tkinter import *
from tkinter import filedialog
window =Tk()
window.title("menu")
window.geometry("350x200")
def openFileText():
filename=filedialog.askopenfilename(initialdir="D:/", title="Chose your file",
filetype=(("txt file","*.txt"),("file format jpg","*.jpg"),("all file","*.*")))
file=open(filename,"r")
konten=file.read()
lbl.configure(text=konten)
lbl=Label(window, text="")
lbl.grid(column=0, row=0)
menu= Menu(window)
item = Menu( menu, tearoff=0)
window.config(menu=menu)
window.mainloop()
Hasilnya