Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # tk_autosuggestion.py
- import tkinter as tk
- root = tk.Tk()
- user_input = tk.StringVar()
- suggestions = []
- entry = tk.Entry(root, textvariable=user_input)
- entry.bind("<Key>", update_suggestions)
- autosuggestion = ['root = Tk()', 'root.geometry("widthxheight+xoffset+yoffset")', 'root.title("string")', 'var$ = ', '(,[dict~])',
- 'Label(root, text="string")', 'Button(root, text="string", command=function)', 'Entry(root, textvariable=var$)',
- 'Checkbutton(root, text="string", variable=var$)', 'Radiobutton(root, text="string", variable=var$)',
- 'Listbox(root, listvariable=var$)', 'Text(root, width=number, height=number)',
- 'Frame(root)', 'Scrollbar(frame)', 'Menu(root)', 'Menu(menu)',
- 'canvas = Canvas(root, width=number, height=number)', 'image = PhotoImage(file="filename.gif")',
- 'scale = Scale(root, from_=number, to=number, orient=HORIZONTAL)', 'spinbox = Spinbox(root, from_=number, to=number)',
- 'message = Message(root, text="string")', 'optionmenu = OptionMenu(root, var$, "choice1", "choice2", "choice3")',
- 'frame.pack()', 'scrollbar.pack(side=RIGHT, fill=Y)', 'menu.add_cascade(label="string", menu=submenu)',
- 'canvas.pack()', 'canvas.create_image(x, y, image=image)', 'scale.pack()', 'spinbox.pack()', 'message.pack()',
- 'optionmenu.pack()', 'widget.grid(row=number, column=number, ...)', 'widget.place(x=number, y=number, ...)',["print", ["(", ["=", ["sep", "end", "file"]], ")"],
- ["import", ["module~"]],
- ["from", ["module~", "import", ["func~"]],
- ["class", ["classname", ["(", ["parentclass~"], ")"], ":"],
- ["def", ["funcname", ["(", ["arg~"], ")"], ":"],
- ["return", ["expr"]],
- ["if", ["expr"], ":",
- ["elif", ["expr"], ":",
- ["else:"],
- ["for", ["var", "in", "iter"], ":"],
- ["while", ["expr"], ":"],
- ["try:",
- ["except", ["Exception", "as", "var"], ":"],
- ["with", ["expr", "as", "var"], ":"],
- ["raise", ["Exception"]],
- ["break"],
- ["continue"],
- ["pass"],
- ["del", ["var"]],
- ["assert", ["expr"]],
- ["yield", ["expr"]],
- ["lambda", ["arg~"], ":", ["expr"]],
- ["global", ["var~"]],
- ["nonlocal", ["var~"]],
- ["async", ["def", ["funcname", ["(", ["arg~"], ")"], ":"],
- ["await", ["expr"]],
- ["range", ["start", "stop", "step"]],
- ["in"],
- ["not in"],
- ["and"],
- ["or"],
- ["not"],
- ["len", ["obj"]],
- ["type", ["obj"]],
- ["str", ["obj"]],
- ["repr", ["obj"]],
- ["int", ["x", "base"]],
- ["float", ["x"]],
- ["complex", ["real", "imag"]],
- ["divmod", ["x", "y"]],
- ["pow", ["x", "y", "z"]],
- ["round", ["number", "ndigits"]],
- ["max", ["iter", "*args", "key"]],
- ["min", ["iter", "*args", "key"]],
- ["sum", ["iter", "start"]],
- ["any", ["iter"]],
- ["all", ["iter"]],
- ["sorted", ["iter", "key", "reverse"]],
- ["reversed", ["seq"]],
- ["enumerate", ["iter", "start"]],
- ["zip", ["*iters"]],
- ["map", ["function", "iter", "*iters"]],
- ["filter", ["function", "iter"]],
- ["abs", ["x"]],
- ["chr", ["i"]],
- ["ord", ["c"]],
- ["bin", ["x"]],
- ["oct", ["x"]],
- ["hex", ["x"]],
- ["bool", ["x"]],
- ["bytearray", ["source", "encoding", "errors"]],
- ["bytes", ["source", "encoding", "errors"]],
- ["complex", ["real", "imag"]],
- ["dict", ["mapping", "**kwargs"]],
- ["dir", ["obj"]],
- ["frozenset", ["iter"]],
- ["list", ["iter"]],
- ["set", ["iter"]],
- ["tuple", ["iter"]],
- ["type", ["obj", "base_type", "dict"]],
- ["vars", ["obj"]],
- ["repr", ["obj"]],
- ["format", ["value", "format_spec"]],
- ["hash", ["obj"]],
- ["memoryview", ["obj"]],
- ["property", ["fget", "fset", "fdel", "doc"]],
- ["staticmethod", ["function"]],
- ["classmethod", ["function"]],
- ["isinstance", ["obj", "classinfo"]],
- ["compile", ["source", "filename", "mode", "flags", "dont_inherit"]],
- ["exec", ["source", "globals", "locals"]],
- ["eval", ["expression", "globals", "locals"]],
- ["globals", [""]],
- ["locals", [""]],
- ["vars", [""]],
- ["dir", [""]],
- ["help", ["obj"]],
- ["ascii", ["obj"]],
- ["repr", ["obj"]],
- ["input", ["prompt"]],
- ["print", ["*objs", "sep", "end", "file", "flush"]],
- ["delattr", ["obj", "name"]],
- ["getattr", ["obj", "name", "default"]],
- ["setattr", ["obj", "name", "value"]],
- ["hasattr", ["obj", "name"]],
- ["id", ["obj"]],
- ["isinstance", ["obj", "classinfo"]],
- ["iter", ["obj", "sentinel"]],
- ["next", ["iterator", "default"]],
- ["len", ["obj"]],
- ["reversed", ["sequence"]],
- ["sorted", ["iterable", "key", "reverse"]],
- ["slice", ["start", "stop", "step"]],
- ["sum", ["iterable", "start"]],
- ["type", ["obj"]],
- ["zip", ["*iterables"]]]]
- listbox = tk.Listbox(root)
- def update_suggestions(event):
- user_input = event.widget.get()
- suggestions = []
- # Update the suggestions list based on the user's input
- for command in autosuggestion:
- if command.startswith(user_input):
- suggestions.append(command)
- # Clear the listbox and refill it with the updated suggestions
- listbox.delete(0, tk.END)
- for suggestion in suggestions:
- listbox.insert(tk.END, suggestion)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement