Advertisement
ALEXANDAR_GEORGIEV

autocomplete_problem

Jun 20th, 2022 (edited)
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.35 KB | None | 0 0
  1. from tkinter import *
  2. from tkinter import ttk
  3.  
  4. window_hint = None
  5. Heading = ['Наименование', 'Мярка', 'Количество']
  6. EntryData = [('', 'кг', 5000),
  7.            ('', 'бр', 5000),
  8.            ('', 'л', 5000),
  9.            ('', 'пак', 5000),
  10.             ]
  11.  
  12.  
  13. def show_hint(event):
  14.     pass
  15.  
  16.     global window_hint
  17.     if window_hint is None:
  18.         window_hint = Toplevel(entry1)  # Закачаме прозореца на подсказката към Entry
  19.         x_entry1 = entry1.winfo_rootx()
  20.         y_entry1 = entry1.winfo_rooty()
  21.         x = x_entry1
  22.         y = y_entry1 + entry1.winfo_height() + 1  # височината на entry1 + 1 пиксел (под полето)
  23.         window_hint.wm_overrideredirect(True)  # Да не се появява заглавието на прозореца
  24.         window_hint.wm_geometry("+%d+%d" % (x, y))
  25.         window_hint.attributes('-topmost', 'true')
  26.         # Create Treeview
  27.         treev = ttk.Treeview(window_hint, show='headings', columns=tuple([str(i) for i in range(1, 4)]), selectmode='extended')
  28.         for i in range(len(Heading)):
  29.             treev.heading(str(i+1), text=Heading[i])
  30.             treev.column(str(i+1))
  31.  
  32.         treev.pack()
  33.  
  34.         # for j in range(len(EntryData)):
  35.         #     data = EntryData[j]
  36.         #     stock = Label(treev, text=str(j+1), width=6).grid(row=j+1, column=0)
  37.         #     msr = Label(treev, text=data[1], width=4).grid(row=j+1, column=1)
  38.         #     qty = Label(treev, text=data[2], width=4).grid(row=j+1, column=2)
  39.     input_text = entry1.get()
  40.     length = len(str(input_text).strip())
  41.     if length <= 0:
  42.         window_hint.destroy()
  43.         window_hint = None
  44.  
  45.  
  46. # data source list,
  47. my_list = ['aecde', 'adba', 'acbd', 'abcd', 'abded',
  48.            'bdbd', 'baba', 'bcbc', 'bdbd']
  49. # Main window
  50. root = Tk()
  51. root.geometry("410x400")  # Size of the window
  52. root.title("Autocomplete")  # Adding a title
  53. font1 = ('Times', 24, 'bold')  # font size and style
  54. # Създаване на Entry
  55. ent_text = StringVar # За да може да ползваме текста в Entry за по-нататъшна обработка
  56. entry1 = Entry(root, textvariable=ent_text,  width=40, bd=3)
  57. entry1.bind('<KeyRelease>', show_hint)  # При пускане на клавиша
  58. entry1.pack()
  59.  
  60.  
  61.  
  62. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement