Attachment 'app2.py'

Download

   1 #!/usr/bin/env python3
   2 '''
   3 '''
   4 from tkinter import *
   5 from tkinter import ttk
   6 def calculate(*args):
   7     try:
   8         value = float(feet.get())
   9         meters.set((0.3048 * value * 10000.0 + 0.5)/10000.0)
  10     except ValueError:
  11         pass
  12 
  13 def chtheme(*args):
  14     c = style.theme_names()*2
  15     style.theme_use(c[c.index(style.theme_use())+1])
  16     curstyle.set(style.theme_use())
  17 
  18 root = Tk()
  19 root.title("Feet to Meters")
  20 style = ttk.Style()
  21 mainframe = ttk.Frame(root, padding="3 3 12 12")
  22 mainframe.grid(column=0, row=0, sticky=(N, W, E, S))
  23 mainframe.columnconfigure(0, weight=1)
  24 mainframe.rowconfigure(0, weight=1)
  25 feet = StringVar()
  26 meters = StringVar()
  27 curstyle = StringVar()
  28 curstyle.set(style.theme_use())
  29 feet_entry = ttk.Entry(mainframe, width=7, textvariable=feet)
  30 feet_entry.grid(column=2, row=1, sticky=(W, E))
  31 ttk.Label(mainframe, textvariable=meters).grid(column=2, row=2, sticky=(W, E))
  32 ttk.Button(mainframe, text="Calculate", command=calculate).grid(column=3, row=3, sticky=W)
  33 ttk.Button(mainframe, textvariable=curstyle, command=chtheme).grid(column=1, row=1, sticky = (N, W))
  34 ttk.Label(mainframe, text="feet").grid(column=3, row=1, sticky=W)
  35 ttk.Label(mainframe, text="is equivalent to").grid(column=1, row=2, sticky=E)
  36 ttk.Label(mainframe, text="meters").grid(column=3, row=2, sticky=W)
  37 for child in mainframe.winfo_children(): child.grid_configure(padx=5, pady=5)
  38 feet_entry.focus()
  39 root.bind('<Return>', calculate)
  40 root.mainloop()

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.

You are not allowed to attach a file to this page.