Advertisement
here2share

# tk_Art_Code_Prompter.py

Feb 22nd, 2025 (edited)
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.83 KB | None | 0 0
  1. # tk_Art_Code_Prompter.py
  2.  
  3. import tkinter as tk
  4. from tkinter import ttk
  5. import os
  6.  
  7. def clear_console():
  8.     os.system('cls')
  9.  
  10. root = tk.Tk()
  11. root.title("# tk_Art_Code_Prompter.py")
  12. root.geometry("1200x600+-10+0")
  13.  
  14. main_frame = ttk.Frame(root)
  15. main_frame.pack(fill=tk.BOTH, expand=True)
  16.  
  17. canvas = tk.Canvas(main_frame)
  18. v_scroll = ttk.Scrollbar(main_frame, orient="vertical", command=canvas.yview)
  19. canvas.configure(yscrollcommand=v_scroll.set)
  20.  
  21. main_frame.grid_rowconfigure(0, weight=1)
  22. main_frame.grid_columnconfigure(0, weight=1)
  23.  
  24. v_scroll.grid(row=0, column=1, sticky="ns")
  25. canvas.grid(row=0, column=0, sticky="nsew")
  26.  
  27. checkbox_frame = ttk.Frame(canvas)
  28. canvas.create_window((0, 0), window=checkbox_frame, anchor="nw")
  29.  
  30. checkbox_items = '''*** anchor {nw/n/ne/w/center/e/sw/s/se}, *** justify text {left/center/right}, *** justify widgets {left/center/right}, *** relief {flat/groove/ridge/raised/sunken}, *** zooming {inward/outward/interactive}, *** {grid()/pack()/place()}, +Canvas, +LEFT, +PIL, +PhotoImage, +blending, +builtin only, +contour drawing, +gradient, +grid_propagate, +interactive art, +morph, +organic art, +particle physics, +procedural generation, +raster art, +ray tracing, +ripple effects, +root.geometry("1200x600+0+0"), +texture mapping, +tile, +vector art, +vertical scrollbar, -after, -classes, -comments, -file reading, -file saving, -ghostscript, -matplotlib, -minimalist art, -numpy, -open, -outline, -padx, -pady, -postscript, -pygame, -random, -save, -scipy, -svg, -titlebar, -turtle, 3D images, Button, CENTER, Checkbutton, Entry, GROOVE, KeyPress, KeyRelease, Listbox, Menubutton, OptionMenu, RAISED, RIDGE, Radiobutton, Scale, Spinbox, Text, algorithmic art, animation, arrow keys, askcolor, askdirectory, askopenfilename, asksaveasfilename, audio-reactive art, bbox, bell, bg color, bind, bind_all, cellular automata, color inversion, coords, create_arc, create_bitmap, create_image, create_line, create_oval, create_polygon, create_rectangle, create_text, create_window, cross-hatching, data visualization art, delete, destroy, disable, embossing, expand, fg color, fill, font (family size style), fractal generation, geometric art, glow effects, grid_bbox, grid_columnconfigure, grid_forget, grid_info, grid_location, grid_remove, grid_rowconfigure, grid_size, hatching, horizontal scrollbar, itemcget, itemconfig, itemconfigure, lift, lower, marching squares, messagebox, minsize, motion blur, move, noise generation, offset, pack_forget, pack_info, pack_propagate, panning, pixel art, pixelation, place_forget, place_info, pointillism, polka dots, radiobutton, resizable, rowspan, scale, selectbackground, selectborderwidth, selectcolor, selectforeground, shading, shadow effects, sliderlength, spirals, stippling, stripes, tag_bind, tag_lower, tag_raise, tag_unbind, tags, title menu, toplevel, transformations, transparency, undo, virtual reality integration, voronoi, waves, winfo_height, winfo_width, wrap, wraplength'''
  31.  
  32. checkbox_items = checkbox_items.split(', ')
  33. font_style = ("Helvetica", 12)
  34. state_vars = []
  35. num_columns = 4
  36. red = '#cc0000'
  37.  
  38. def cycle_color(i):
  39.     destroy()
  40.     label = lbl[i]
  41.     current_bg = label.cget("bg")
  42.     if current_bg == "#f0f0f0":  # Default gray
  43.         label.config(bg="green", fg="white")
  44.         state_vars[i] = "include"
  45.     elif current_bg == "green":
  46.         label.config(bg=red, fg="white")
  47.         state_vars[i] = "exclude"
  48.     elif current_bg == red:
  49.         label.config(bg="#f0f0f0", fg="gray")
  50.         state_vars[i] = "neutral"
  51.  
  52. def set_colors(color=None, prompt=None):
  53.     global fg0, bg0, text
  54.     fg0, bg0 = 'white', color
  55.     if not text[0].isalpha():
  56.         text = checkbox_items[i] = text[1:]
  57.     state_vars[-1] = prompt
  58.    
  59. def destroy():
  60.     try:
  61.         popup.destroy()
  62.     except:
  63.         0
  64.    
  65. def open_selection_popup(event, i):
  66.     global popup
  67.     destroy()
  68.     x, y = event.x_root,event.y_root
  69.     x -= 20
  70.     y -= 20
  71.     items = lbl[i, 'multi']
  72.     popup = tk.Toplevel(root)
  73.     popup.geometry(f"+{x}+{y}")
  74.     popup.overrideredirect(True)
  75.     options = items['options']
  76.     selected_option = tk.StringVar()
  77.     if options:
  78.         selected_option.set(options[0])
  79.     else:
  80.         selected_option.set("")
  81.  
  82.     for opt in options:
  83.         rb = tk.Radiobutton(popup, text=opt, variable=selected_option, value=opt)
  84.         rb.pack(anchor="w")
  85.        
  86.     change_text(lbl[i], items['text'] + options[0])
  87.  
  88.     def include_action():
  89.         if selected_option.get():
  90.             state_vars[i] = "include"
  91.             txt = f"{items['text']}{selected_option.get()}"
  92.             lbl[i].config(text=txt, bg="green", fg="white")
  93.             checkbox_items[i] = txt
  94.             popup.destroy()
  95.  
  96.     def neutral_action():
  97.         state_vars[i] = "neutral"
  98.         lbl[i].config(text=items['text'], bg="#f0f0f0", fg="gray")
  99.         popup.destroy()
  100.  
  101.     tk.Button(popup, text="Include", command=include_action).pack(fill="x")
  102.     tk.Button(popup, text="Set To Neutral", command=neutral_action).pack(fill="x")
  103.     tk.Button(popup, text="Cancel", command=popup.destroy).pack(fill="x")
  104.  
  105. def change_text(widget, txt):
  106.     widget.config(text=txt)
  107.  
  108. lbl = {}
  109. for i, text in enumerate(checkbox_items):
  110.     row = i // num_columns
  111.     col = i % num_columns
  112.  
  113.     state_vars.append("neutral")  # Default state
  114.  
  115.     fg0, bg0 = "gray", "#f0f0f0"  # Default gray
  116.     if text[0] == '+':
  117.         set_colors("green", "include")
  118.     elif text[0] == '-':
  119.         set_colors(red, "exclude")
  120.  
  121.     lbl[i] = tk.Label(checkbox_frame, text=text, fg=fg0, bg=bg0, width=30, anchor="w", font=font_style)
  122.     lbl[i].grid(row=row, column=col, sticky="w", padx=5)
  123.     if "{" in text:
  124.         text, options = text.split("{")
  125.         options = options.split("}")[0]
  126.         options = options.split("/")
  127.         item_data = {
  128.             'text': text,
  129.             'options': options,
  130.             'state': "neutral"
  131.         }
  132.         lbl[i, 'multi'] = item_data
  133.         lbl[i].bind("<Button-1>", lambda e, idx=i: open_selection_popup(e, idx))
  134.         txt = f"{text}{options[0]}"
  135.         checkbox_items[i] = txt
  136.         change_text(lbl[i], txt)
  137.     else:  
  138.         lbl[i].bind("<Button-1>", lambda e, idx=i: cycle_color(idx))
  139.  
  140. checkbox_frame.update_idletasks()
  141. canvas.config(scrollregion=canvas.bbox("all"))
  142.  
  143. def o(p):
  144.     return "\n".join(f"* {item.replace('** ', '')}" for item in p)
  145.  
  146. def generate_prompt():
  147.     clear_console()
  148.     item_states = {'include' : [], 'exclude' : []}
  149.     for i, state in enumerate(state_vars):
  150.         if state in item_states:
  151.             item_states[state].append(checkbox_items[i])
  152.            
  153.     include_items, exclude_items = item_states['include'], item_states['exclude']
  154.  
  155.     prompt = "Create a Python script using Tkinter with the following requirements:\n"
  156.     if include_items:
  157.         prompt += "Include these elements (needs to be present):\n" + o(include_items) + "\n"
  158.     if exclude_items:
  159.         prompt += "Exclude these elements (must not be present):\n" + o(exclude_items) + "\n"
  160.     if not include_items and not exclude_items:
  161.         prompt += "No specific elements selected for inclusion or exclusion.\n"
  162.  
  163.     print(prompt)
  164.  
  165. generate_btn = tk.Button(root, text="Generate Code Template", command=generate_prompt, bg='skyblue', font=font_style)
  166. generate_btn.pack(pady=3)
  167.  
  168. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement