, # using a try block due to the changes in python 2 and 3 , try: , import Tkinter as tk # python 2 , except: , import tkinter as tk # python 3 , ,
, # create root window , root = tk.Tk() , , # root window geometry , root.geometry(800x600) , , # display root window and children , root.mainloop() , ,
, # create label , lbl = tk.Label(root, text=DQsome textDQ) , , # display label , lbl.pack() , , # create label from variable , var = tk.StringVar() , var.set(DQThis text came from a variableDQ) , lbl_2 = tk.Label( root, textvariable = var ) , lbl_2.pack() ,
, # create button , btn_1 = tk.Button( root, text = DQThis text came from the button text propertyDQ) , btn_1.pack() , , # button with a function call , def close_window(): , root.destroy() , , btn_2 = tk.Button( root, text = DQClose Window With a FunctionDQ, command = close_window) , btn_2.pack() , , # button with a system call directly , btn_3 = tk.Button( root, text = DQClose Window With a System CallDQ, command = root.destroy) , btn_3.pack() ,
, # entry , def display_user_name(): , lbl_4_value.set(entry_1.get()) , , user_name = tk.StringVar() , lbl_4_value = tk.StringVar() , , lbl_3 = tk.Label( text = DQUser NameDQ) , lbl_3.pack() , , entry_1 = tk.Entry(root, textvariable=user_name) , entry_1.pack() , , btn_4 = tk.Button(root, text=DQDisplay Entry ValueDQ, command=display_user_name) , btn_4.pack() , , lbl_4 = tk.Label(root, textvariable=lbl_4_value) , lbl_4.pack() ,
, # label frame , labelframe = tk.LabelFrame(root, text = DQThis is a LabelFrameDQ) , labelframe.pack(fill = DQbothDQ, expand = DQyesDQ) , , lbl_5 = tk.Label(labelframe, text = DQInside the LabelFrameDQ) , lbl_5.pack() ,
, # file browser , from tkinter import filedialog , from tkinter import * , , root = Tk() , root.filename = filedialog.askopenfilename(initialdir = DQ/homeDQ,title = DQSelect fileDQ) , print (root.filename) ,