Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # tk_Art_Code_Prompter.py
- import tkinter as tk
- from tkinter import ttk
- import os
- def clear_console():
- os.system('cls')
- root = tk.Tk()
- root.title("# tk_Art_Code_Prompter.py")
- root.geometry("1200x600+-10+0")
- main_frame = ttk.Frame(root)
- main_frame.pack(fill=tk.BOTH, expand=True)
- canvas = tk.Canvas(main_frame)
- v_scroll = ttk.Scrollbar(main_frame, orient="vertical", command=canvas.yview)
- canvas.configure(yscrollcommand=v_scroll.set)
- main_frame.grid_rowconfigure(0, weight=1)
- main_frame.grid_columnconfigure(0, weight=1)
- v_scroll.grid(row=0, column=1, sticky="ns")
- canvas.grid(row=0, column=0, sticky="nsew")
- checkbox_frame = ttk.Frame(canvas)
- canvas.create_window((0, 0), window=checkbox_frame, anchor="nw")
- 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'''
- checkbox_items = checkbox_items.split(', ')
- font_style = ("Helvetica", 12)
- state_vars = []
- num_columns = 4
- red = '#cc0000'
- def cycle_color(i):
- destroy()
- label = lbl[i]
- current_bg = label.cget("bg")
- if current_bg == "#f0f0f0": # Default gray
- label.config(bg="green", fg="white")
- state_vars[i] = "include"
- elif current_bg == "green":
- label.config(bg=red, fg="white")
- state_vars[i] = "exclude"
- elif current_bg == red:
- label.config(bg="#f0f0f0", fg="gray")
- state_vars[i] = "neutral"
- def set_colors(color=None, prompt=None):
- global fg0, bg0, text
- fg0, bg0 = 'white', color
- if not text[0].isalpha():
- text = checkbox_items[i] = text[1:]
- state_vars[-1] = prompt
- def destroy():
- try:
- popup.destroy()
- except:
- 0
- def open_selection_popup(event, i):
- global popup
- destroy()
- x, y = event.x_root,event.y_root
- x -= 20
- y -= 20
- items = lbl[i, 'multi']
- popup = tk.Toplevel(root)
- popup.geometry(f"+{x}+{y}")
- popup.overrideredirect(True)
- options = items['options']
- selected_option = tk.StringVar()
- if options:
- selected_option.set(options[0])
- else:
- selected_option.set("")
- for opt in options:
- rb = tk.Radiobutton(popup, text=opt, variable=selected_option, value=opt)
- rb.pack(anchor="w")
- change_text(lbl[i], items['text'] + options[0])
- def include_action():
- if selected_option.get():
- state_vars[i] = "include"
- txt = f"{items['text']}{selected_option.get()}"
- lbl[i].config(text=txt, bg="green", fg="white")
- checkbox_items[i] = txt
- popup.destroy()
- def neutral_action():
- state_vars[i] = "neutral"
- lbl[i].config(text=items['text'], bg="#f0f0f0", fg="gray")
- popup.destroy()
- tk.Button(popup, text="Include", command=include_action).pack(fill="x")
- tk.Button(popup, text="Set To Neutral", command=neutral_action).pack(fill="x")
- tk.Button(popup, text="Cancel", command=popup.destroy).pack(fill="x")
- def change_text(widget, txt):
- widget.config(text=txt)
- lbl = {}
- for i, text in enumerate(checkbox_items):
- row = i // num_columns
- col = i % num_columns
- state_vars.append("neutral") # Default state
- fg0, bg0 = "gray", "#f0f0f0" # Default gray
- if text[0] == '+':
- set_colors("green", "include")
- elif text[0] == '-':
- set_colors(red, "exclude")
- lbl[i] = tk.Label(checkbox_frame, text=text, fg=fg0, bg=bg0, width=30, anchor="w", font=font_style)
- lbl[i].grid(row=row, column=col, sticky="w", padx=5)
- if "{" in text:
- text, options = text.split("{")
- options = options.split("}")[0]
- options = options.split("/")
- item_data = {
- 'text': text,
- 'options': options,
- 'state': "neutral"
- }
- lbl[i, 'multi'] = item_data
- lbl[i].bind("<Button-1>", lambda e, idx=i: open_selection_popup(e, idx))
- txt = f"{text}{options[0]}"
- checkbox_items[i] = txt
- change_text(lbl[i], txt)
- else:
- lbl[i].bind("<Button-1>", lambda e, idx=i: cycle_color(idx))
- checkbox_frame.update_idletasks()
- canvas.config(scrollregion=canvas.bbox("all"))
- def o(p):
- return "\n".join(f"* {item.replace('** ', '')}" for item in p)
- def generate_prompt():
- clear_console()
- item_states = {'include' : [], 'exclude' : []}
- for i, state in enumerate(state_vars):
- if state in item_states:
- item_states[state].append(checkbox_items[i])
- include_items, exclude_items = item_states['include'], item_states['exclude']
- prompt = "Create a Python script using Tkinter with the following requirements:\n"
- if include_items:
- prompt += "Include these elements (needs to be present):\n" + o(include_items) + "\n"
- if exclude_items:
- prompt += "Exclude these elements (must not be present):\n" + o(exclude_items) + "\n"
- if not include_items and not exclude_items:
- prompt += "No specific elements selected for inclusion or exclusion.\n"
- print(prompt)
- generate_btn = tk.Button(root, text="Generate Code Template", command=generate_prompt, bg='skyblue', font=font_style)
- generate_btn.pack(pady=3)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement