First TKInter Python Program

from tkinter import *root = Tk()root.title("Hello World")root.geometry("800x600")def callback_go ():Label(root, text="It worked!").grid(row=2, column=0, sticky=W)def quit_application ():root.destroy()menubar = Menu(root)# create a pulldown menu, and add it to the menu barfilemenu = Menu(menubar, tearoff=0)filemenu.add_command(label="Open", command=callback_go)filemenu.add_command(label="Save", command=callback_go)filemenu.add_separator()filemenu.add_command(label="Exit", command=quit_application)menubar.add_cascade(label="File", menu=filemenu)# create more pulldown menuseditmenu = Menu(menubar, tearoff=0)editmenu.add_command(label="Cut", command=callback_go)editmenu.add_command(label="Copy", command=callback_go)editmenu.add_command(label="Paste", command=callback_go)menubar.add_cascade(label="Edit", menu=editmenu)helpmenu = Menu(menubar, tearoff=0)helpmenu.add_command(label="About", command=callback_go)menubar.add_cascade(label="Help", menu=helpmenu)# display the menuroot.config(menu=menubar)Label(root, text="Hello World").grid(row=0, column=0, sticky=W)Label(root, text="Please enter your name:").grid(row=1, column=0, sticky=W)Entry(root).grid(row=1, column=1, sticky=E)Button(root, text="Go", command=callback_go).grid(row=1, column=2, sticky=E)Button(root, text="Quit", command=quit_application).grid(row=2, column=3, sticky=E)root.mainloop()

Previous
Previous

Linking to free web content is.... Legal!

Next
Next

PC Pro Podcast 298