Advertisement
here2share

# TkGUI_all_in_one.py

Feb 7th, 2022
1,084
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 13.96 KB | None | 1 0
  1. # TkGUI_all_in_one.py
  2.  
  3. # To help create Modern Gui Using Tkinter (A Work In Progess)
  4.  
  5. import os
  6. from tkinter import Frame
  7. from tkinter.constants import RADIOBUTTON
  8.  
  9.  
  10. app_name=input("Enter your app name : ")
  11. if not app_name:
  12.     app_name = "quick_demo"
  13.  
  14. """
  15. f =open(app_name+".py","a+")
  16.  
  17. f.write('''import tkinter as tk''')
  18. """
  19.  
  20. import tkinter
  21.  
  22. root = tkinter.Tk()
  23. root.title("'''+app_name+'''")
  24. """
  25. root.iconbitmap('icon.ico')
  26. """
  27. root.option_add("*tearOff", False) # This is always a good idea''')
  28.  
  29. """
  30. f.flush()
  31. """
  32.  
  33. ########################################### Functions ###########################################
  34.  
  35.  
  36. def text():
  37.     print("\nADD TEXT :-")
  38.     widget_name=input("\n   Enter widget name : ")
  39.     layout= input("   Add widget to(root / custom_widget) :")
  40.     Label= input("   Add text here :")
  41.     fg_color= input("   Add foreground colour : ")  
  42.     font=input("   Enter font name : ")
  43.     align=input("   Align text to ( left / right / center ): ")
  44.     row=input("   Add row number : ")
  45.     column=input("   Add column number : ")
  46.     pady=input("   Add y spacing : ")
  47.     f.write('''
  48. # Label
  49. '''+widget_name+''' = ttk.Label('''+layout+''', text="'''+Label+'''",font="'''+font+'''" ,justify="'''+align+'''",foreground="'''+fg_color+'''")
  50. '''+widget_name+'''.grid(row='''+row+''', column='''+column+''', pady='''+pady+''', columnspan=2)''')
  51.     print("\nText added successfully !\n")
  52.     f.flush()
  53.  
  54. def button():
  55.     print("\nSelect Button Style :-")
  56.     print("\n 1. Normal Button")
  57.     print(" 2. Accent Button")
  58.     print(" 3. Toggle button")
  59.     button_type = input("\n   Enter Button Style [1-3] :")
  60.     widget_name=input("   Enter widget name : ")
  61.     layout= input("   Add widget to(root / custom_widget) :")
  62.     text=input("\n   Add text : ")
  63.     row=input("   Add row number :")
  64.     column=input("   Add column number :")
  65.     padx=input("   Add x spacing :")
  66.     pady=input("   Add y spacing :")
  67.     if button_type=="1":
  68.         f.write('''
  69. '''+widget_name+''' = ttk.Button('''+layout+''', text="'''+text+'''")
  70. '''+widget_name+'''.grid(row='''+row+''', column='''+column+''', padx='''+padx+''', pady='''+pady+''', sticky="nsew")''')
  71.         f.flush()
  72.         print("\nButton added successfully !\n")
  73.     if button_type=="2":
  74.         f.write('''
  75. '''+widget_name+''' = ttk.Button('''+layout+''', text="'''+text+'''",style="AccentButton")
  76. '''+widget_name+'''.grid(row='''+row+''', column='''+column+''', padx='''+padx+''', pady='''+pady+''', sticky="nsew")''')
  77.         f.flush()
  78.         print("\nButton added successfully !\n")
  79.     if button_type=="3":
  80.         f.write('''
  81. '''+widget_name+''' = ttk.Button('''+layout+''', text="'''+text+'''",style="ToggleButton")
  82. '''+widget_name+'''.grid(row='''+row+''', column='''+column+''', padx='''+padx+''', pady='''+pady+''', sticky="nsew")''')
  83.         f.flush()
  84.         print("\nButton added successfully !\n")
  85.    
  86.    
  87. def wedget_frame():
  88.     print("\nADD Widget Frame :-")
  89.     widget_name=input("\n   Enter widget name : ")
  90.     layout= input("   Add widget to(root / custom_widget) :")
  91.     padding=input("   Add spacing (x,y,z,value) : ")
  92.     row=input("   Add row number : ")
  93.     column=input("   Add column number : ")
  94.     padx=input("   Add x spacing (value1,value2) : ")
  95.     pady=input("   Add y spacing (value1,value2) : ")
  96.     index=input("   Add index number : ")
  97.     weight=input("   Add border weight :")
  98.     f.write('''
  99. '''+widget_name+''' = ttk.Frame('''+layout+''', padding='''+ padding+''')
  100. '''+widget_name+'''.grid(row='''+row+''', column='''+column+''', padx='''+padx+''', pady='''+pady+''', sticky="nsew", rowspan=3)
  101. '''+widget_name+'''.columnconfigure(index='''+index+''', weight='''+weight+''')''')
  102.     print("\nWidget Frame added successfully !\n")
  103.     f.flush()
  104.  
  105. def entry_box():
  106.     print("\nADD Entry Frame :-")
  107.     widget_name=input("\n   Enter widget name : ")
  108.     layout= input("   Add widget to(root / custom_widget) :")
  109.     l_text=input("   Add text : ")
  110.     row=input("   Add row number : ")
  111.     column=input("   Add column number : ")
  112.     padx=input("   Add x spacing (value1,value2) : ")
  113.     pady=input("   Add y spacing (value1,value2) : ")
  114.  
  115.     f.write(  '''  
  116. # Entry
  117. '''+widget_name+''' = ttk.Entry('''+layout+''')
  118. '''+widget_name+'''.insert(0, "'''+ l_text +'''")
  119. '''+widget_name+'''.grid(row='''+row+''', column='''+column+''', padx='''+padx+''', pady='''+pady+''', sticky="ew")''')
  120.     f.flush()
  121.     print("\nEntry added successfully !\n")
  122.  
  123. def radio_button():
  124.     print("\nADD Radio Button :-")
  125.     widget_name=input("\n   Enter widget name : ")
  126.     layout= input("   Add widget to(root / custom_widget) :")
  127.     text_radio=input("   Add text here : ")
  128.     row=input("   Add row number : ")
  129.     column=input("   Add column number : ")
  130.     padx=input("   Add x spacing (value1,value2) : ")
  131.     pady=input("   Add y spacing (value1,value2) : ")
  132.  
  133.     f.write(
  134. '''
  135. '''+widget_name+''' = ttk.Radiobutton('''+layout+''', text="'''+text_radio+'''")
  136. '''+widget_name+'''.grid(row='''+row+''', column='''+column+''', padx='''+padx+''', pady='''+pady+''', sticky="nsew")''')
  137.     f.flush()
  138.     print("\nRadio Button added successfully !\n")
  139.    
  140.  
  141. def Spinbox():
  142.     print("\nADD Spinbox :-")
  143.     widget_name=input("\n   Enter widget name : ")
  144.     layout= input("   Add widget to(root / custom_widget) :")
  145.     row=input("   Add row number : ")
  146.     column=input("   Add column number : ")
  147.     padx=input("   Add x spacing (value1,value2) : ")
  148.     pady=input("   Add y spacing (value1,value2) : ")
  149.  
  150.     f.write(
  151. '''
  152. '''+widget_name+''' = ttk.Spinbox('''+layout+''', from_=0, to=100, increment=0.1)
  153. '''+widget_name+'''.insert(0, "'''+ text+'''")
  154. '''+widget_name+'''.grid(row='''+row+''', column='''+column+''', padx='''+padx+''', pady='''+pady+''', sticky="ew")''')
  155.  
  156.     f.flush()
  157.     print("\nSpinbox added successfully !\n")
  158.  
  159. def Combobox():
  160.     print("\nADD Combobox :-")
  161.     widget_name=input("\n   Enter widget name : ")
  162.     layout= input("   Add widget to(root / custom_widget) :")
  163.     row=input("   Add row number : ")
  164.     column=input("   Add column number : ")
  165.     padx=input("   Add x spacing (value1,value2) : ")
  166.     pady=input("   Add y spacing (value1,value2) : ")
  167.  
  168.     f.write(
  169. '''
  170. combo_list = ["Combobox", "Editable item 1", "Editable item 2"]
  171.  
  172. '''+widget_name+''' = ttk.Combobox('''+layout+''',values=combo_list)
  173. '''+widget_name+'''.combobox.current(0)
  174. '''+widget_name+'''.grid(row='''+row+''', column='''+column+''', padx='''+padx+''', pady='''+pady+''', sticky="ew")''')
  175.     f.flush()
  176.     print("\nCombobox added successfully !\n")
  177.  
  178.    
  179. def Switch():
  180.     print("\nADD Switch :-")
  181.     widget_name=input("\n   Enter widget name : ")
  182.     layout= input("   Add widget to(root / custom_widget) :")
  183.     add_text=input("   Add text here : ")
  184.     row=input("   Add row number : ")
  185.     column=input("   Add column number : ")
  186.     padx=input("   Add x spacing (value1,value2) : ")
  187.     pady=input("   Add y spacing (value1,value2) : ")
  188.  
  189.  
  190.     f.write(
  191. '''
  192. # Switch
  193. '''+widget_name+''' = ttk.Checkbutton('''+layout+''', text="'''+add_text+'''", style="Switch")
  194. '''+widget_name+'''.grid(row='''+row+''', column='''+column+''', padx='''+padx+''', pady='''+pady+''', sticky="nsew") ''')
  195.     f.flush()
  196.     print("\nCombobox added successfully !\n")
  197.  
  198. def frame():
  199.     print("\nADD Frame :-")
  200.     widget_name=input("\n   Enter widget name : ")
  201.     layout= input("   Add widget to(root / custom_widget) :")
  202.     add_text=input("   Add text here : ")
  203.     padding=input("   Add Spacing : ")
  204.     row=input("   Add row number : ")
  205.     column=input("   Add column number : ")
  206.     padx=input("   Add x spacing (value1,value2) : ")
  207.     pady=input("   Add y spacing (value1,value2) : ")
  208.  
  209.  
  210.     f.write('''
  211. # Create a Frame
  212. '''+widget_name+''' = ttk.LabelFrame('''+layout+''', text="'''+add_text+'''", padding='''+padding+''')
  213. '''+widget_name+'''.grid(row='''+row+''', column='''+column+''', padx='''+padx+''', pady='''+pady+''', sticky="nsew") ''')
  214.     f.flush()
  215.     print("\nFrame added successfully !\n")
  216.  
  217. def Slider():
  218.     print("\nADD Slider :-")
  219.     widget_name=input("\n   Enter widget name : ")
  220.     layout= input("   Add widget to(root / custom_widget) :")
  221.     row=input("   Add row number : ")
  222.     column=input("   Add column number : ")
  223.     padx=input("   Add x spacing (value1,value2) : ")
  224.     pady=input("   Add y spacing (value1,value2) : ")
  225.  
  226.  
  227.     f.write(
  228. '''
  229. g = tk.DoubleVar(value=75.0)
  230. '''+widget_name+''' = ttk.Scale('''+layout+''', from_=100, to=0, variable=g, command=lambda event: g.set('''+widget_name+'''.get()))
  231. '''+widget_name+'''.grid(row='''+row+''', column='''+column+''', padx='''+padx+''', pady='''+pady+''', sticky="ew")
  232. ''')
  233.     f.flush()
  234.     print("\nSlider added successfully !\n")
  235.  
  236. def Progressbar():
  237.     print("\nProgressbar :-")
  238.     widget_name=input("\n   Enter widget name : ")
  239.     layout= input("   Add widget to(root / custom_widget) :")
  240.     value=input("\n   Enter value here : ")
  241.     row=input("   Add row number : ")
  242.     column=input("   Add column number : ")
  243.     padx=input("   Add x spacing (value1,value2) : ")
  244.     pady=input("   Add y spacing (value1,value2) : ")
  245.  
  246.  
  247.     f.write(
  248. '''
  249. g = tk.DoubleVar(value=75.0)
  250. '''+widget_name+''' = ttk.Progressbar('''+layout+''', value='''+value+''', variable=g, mode="determinate")
  251. '''+widget_name+'''.grid(row='''+row+''', column='''+column+''', padx='''+padx+''', pady='''+pady+''', sticky="ew")
  252. ''')
  253.     f.flush()
  254.     print("\nProgressbar added successfully !\n")
  255.  
  256.  
  257. def run():
  258.     f=open(app_name+".py")
  259.     output = []
  260.  
  261.     for line in f:
  262.  
  263.         if not "root.mainloop()" in line:
  264.  
  265.             output.append(line)
  266.  
  267.     f.close()
  268.  
  269.     f = open("Run_Demo.py", 'w')
  270.  
  271.     f.writelines(output)
  272.     f.write('''\nroot.mainloop()''')
  273.     f.flush()
  274.     os.popen("python Run_Demo.py")
  275.     print("Running "+app_name+".py")
  276.  
  277. def export():
  278.     commands=input("Enter Commands here (--onedir / --console) : ")
  279.     os.popen('''pyinstaller --noconfirm '''+commands+''' --icon "icon.ico" "'''+app_name+'''.py"''')
  280.  
  281. def image():
  282.     print("\nADD Image (Not supported yet!) ")
  283.    
  284.  
  285.  
  286.  
  287.  
  288.  
  289.  
  290.  
  291.  
  292.  
  293. ################################# MAIN APP ####################################################################
  294.  
  295. app_size = input("Enter size of "+ app_name +" (w x h) : ")
  296.  
  297. """
  298. f.write('''
  299. root.geometry("'''+ app_size + '''")''')
  300.  
  301. f.flush()
  302. """
  303.  
  304. app_R= input("Do you want to make "+ app_name +" responsive (y/n) : ")
  305.  
  306. """
  307. if app_R=="y":
  308.    f.write('''
  309. root.columnconfigure(index=0, weight=1)
  310. root.columnconfigure(index=1, weight=1)
  311. root.columnconfigure(index=2, weight=1)
  312. root.rowconfigure(index=0, weight=1)
  313. root.rowconfigure(index=1, weight=1)
  314. root.rowconfigure(index=2, weight=1)
  315. sizegrip = ttk.Sizegrip(root)
  316. sizegrip.grid(row=100, column=100, padx=(0, 5), pady=(0, 5))''')
  317.    f.flush()
  318.  
  319. if app_R=="n":
  320.    f.write('''
  321. root.columnconfigure(index=0, weight=1)
  322. root.columnconfigure(index=1, weight=1)
  323. root.columnconfigure(index=2, weight=1)
  324. root.rowconfigure(index=0, weight=1)
  325. root.rowconfigure(index=1, weight=1)
  326. root.rowconfigure(index=2, weight=1)
  327. root.resizable(False,False)'''  )
  328.    f.flush()
  329. """
  330.  
  331. app_theme=input("Select theme for "+ app_name +" (dark/light) :")
  332.  
  333. """
  334. if app_theme== "dark" :
  335.    f.write('''# Create a style
  336. style = ttk.Style(root)
  337.  
  338. # Import the tcl file
  339. root.tk.call("source", "proxttk-dark.tcl")
  340.  
  341. # Set the theme with the theme_use method
  342. style.theme_use("proxttk-dark")
  343.  
  344. d = tk.IntVar(value=2)''')
  345. else:
  346.    f.write('''# Create a style
  347. style = ttk.Style(root)
  348.  
  349. # Import the tcl file
  350. root.tk.call("source", "proxttk.tcl")
  351.  
  352. # Set the theme with the theme_use method
  353. style.theme_use("proxttk")
  354.  
  355. d = tk.IntVar(value=2)''')
  356.  
  357. f.flush()
  358. """
  359.  
  360.    
  361. print(
  362.     115*"-"
  363.  
  364. )
  365. print(app_name)
  366.      
  367. def print_menu():       ## Your menu design here
  368.     print ("\n",50 * "-" , "Add Widgets" , 50 * "-","\n")
  369.     print ("\n1. Text\n")
  370.     print ("2. Widget Frame\n")
  371.     print ("3. Button\n")
  372.     print ("4. Image\n")
  373.     print ("5. Entry Box\n")
  374.     print ("6. Spinbox\n")
  375.     print ("7. Combobox\n")
  376.     print ("8. Switch\n")
  377.     print ("9. Frame\n")
  378.     print ("10. Slider\n")
  379.     print ("11. Progressbar\n")
  380.     print ("12. Radio Button\n")
  381.     print ("13. Run Final "+app_name+"\n")
  382.     print ("14. Export\n")
  383.     print ("15. Exit\n")
  384.     print ("\n",115 * "-")
  385.  
  386. loop=True
  387.  
  388. while loop:          ## While loop which will keep going until loop = False
  389.     print_menu()    ## Displays menu
  390.     choice = input("Enter your choice [1-15]: ")
  391.    
  392.     if choice=="1":    
  393.         text()
  394.     elif choice=="2":
  395.         wedget_frame()
  396.        
  397.     elif choice=="3":
  398.         button()
  399.        
  400.     elif choice=="4":
  401.         image()
  402.  
  403.     elif choice=="5":
  404.         entry_box()
  405.         ## You can add your code or functions here
  406.     elif choice=="6":
  407.         Spinbox()
  408.         ## You can add your code or functions here  
  409.     elif choice=="7":
  410.         Combobox()
  411.         ## You can add your code or functions here  
  412.     elif choice=="8":
  413.         Switch()
  414.         ## You can add your code or functions here  
  415.     elif choice=="9":
  416.         frame()
  417.         ## You can add your code or functions here  
  418.     elif choice=="10":
  419.         Slider()
  420.         ## You can add your code or functions here  
  421.     elif choice=="11":
  422.         Progressbar()
  423.         ## You can add your code or functions here  
  424.     elif choice=="12":
  425.         radio_button()
  426.         ## You can add your code or functions here  
  427.     elif choice=="13":
  428.         run()
  429.         ## You can add your code or functions here  
  430.     elif choice=="14":
  431.         export()
  432.         ## You can add your code or functions here  
  433.     elif choice=="15":
  434.  
  435.         ## You can add your code or functions here
  436.         loop=False # This will make the while loop to end as not value of loop is set to False
  437.     else:
  438.         # Any integer inputs other than values 1-5 we print an error message
  439.         input("Wrong option selection. Enter any key to try again..")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement