forked from davicfg/Tkinter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tk4.py
67 lines (44 loc) · 1.49 KB
/
tk4.py
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import sys
from tkinter import *
from tkinter import filedialog
def mHello():
mText=ment.get()
mlabel1 = Label(myApp,text=mText).pack()
def myNew():
mlabel1 = Label(myApp,text="YO").pack()
def myOpen():
myOpen = filedialog.askopenfile()
mlabel4 = Label(myApp,text=myOpen).pack()
def mAbout():
messagebox.showinfo(title="About",message="This is the about box")
def mQuit():
mExit = messagebox.askyesno(title="Quit", message="Are you sure")
if mExit > 0:
myApp.destroy()
myApp = Tk()
#create a string variable
ment = StringVar()
#set the size of window
myApp.geometry('450x450+200+200')
myApp.title('Myapp')
mLabel = Label(myApp,text='my label').pack()
mButton = Button(myApp,text ='OK', command = mHello).pack()
#set the ment variable from the text entry box
mEntry = Entry(myApp,textvariable=ment).pack()
#create the menubar
menubar = Menu(myApp)
#create the file component of that menubar
filemenu = Menu(menubar, tearoff=0)
#Add the sub headings to the file menu
filemenu.add_command(label="New", command=myNew)
filemenu.add_command(label="Open", command=myOpen)
filemenu.add_command(label="Save As...")
filemenu.add_command(label="Close", command=mQuit)
menubar.add_cascade(label="File",menu=filemenu)
helpmenu = Menu(menubar, tearoff=0)
helpmenu.add_command(label="Help docs")
helpmenu.add_command(label="About",command=mAbout)
menubar.add_cascade(label="Help",menu=helpmenu)
#add menubar to the window
myApp.config(menu=menubar)
myApp.mainloop()