m8_

Addendum_tk

m8_
Mar 27th, 2019
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.33 KB | None | 0 0
  1. #import os
  2. import tkinter as tk
  3. from tkinter import StringVar, OptionMenu, Button, messagebox, Frame
  4. from mani_functions import _1_check, _2_check, _3_check
  5. from pathlib import Path
  6.  
  7. # create and title the window
  8. root = tk.Tk()
  9. root.title("Addendum")
  10.  
  11. # Add a grid
  12. mainframe = Frame(root)
  13. mainframe.grid(column=0,row=0, sticky="" )
  14. mainframe.columnconfigure(0, weight = 1)
  15. mainframe.rowconfigure(0, weight = 1)
  16. mainframe.pack(pady = 0, padx = 75)
  17.  
  18. # list of options for dropdown menu
  19. optionList = ['Check 1', 'Check 2', 'Check 3']
  20.  
  21. # dictionary of functions
  22. funct_Dict = {
  23.         'Check 1': _1_check,
  24.         'Check 2': _2_check,
  25.         'Check 3': _3_check
  26. }
  27.  
  28. # path to save file
  29. file = Path('C:/Desktop/Addendum.xlsx')
  30.  
  31. def func(value):
  32.     try:
  33.         print(value)
  34.         funct_Dict[value]()
  35.     except:
  36.         root.quit()
  37.         root.destroy()
  38.  
  39. def on_closing():
  40.     if messagebox.askokcancel("Quit", "Do you want to quit?"):
  41.         root.quit()
  42.         root.destroy()
  43.        
  44. # create tkinter variables and OptionMenu
  45. root.dropVar=StringVar(root)
  46. root.dropVar.set("Select a file")
  47. root.dropMenu = OptionMenu(root, root.dropVar, *optionList, command=func)
  48. root.quitButton = Button(root, text='Quit', command=root.quit)
  49. root.dropMenu.pack()
  50.  
  51. root.protocol("WM_DELETE_WINDOW", on_closing)
  52. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment