Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- import re # import regular expression library
- from tkinter import END
- my_w = tk.Tk()
- my_w.geometry("410x400") # Size of the window
- my_w.title("plus2net.com") # Adding a title
- font1 = ('Times', 24, 'bold') # font size and style
- l0 = tk.Label(text='Autocomplete', font=font1) # adding label at top
- l0.grid(row=0, column=1)
- # data source list,
- my_list = ['aecde', 'adba', 'acbd', 'abcd', 'abded',
- 'bdbd', 'baba', 'bcbc', 'bdbd']
- def my_upd(my_widget): # On selection of option
- my_w = my_widget.widget
- index = int(my_w.curselection()[0]) # position of selection
- value = my_w.get(index) # selected value
- e1_str.set(value) # set value for string variable of Entry
- l1.delete(0, END) # Delete all elements of Listbox
- def my_down(my_widget): # down arrow is clicked
- l1.focus() # move focus to Listbox
- l1.selection_set(0) # select the first option
- e1_str = tk.StringVar() # string variable
- e1 = tk.Entry(my_w, textvariable=e1_str, font=font1) # entry
- e1.grid(row=1, column=1, padx=10, pady=0)
- # listbox
- l1 = tk.Listbox(my_w, height=6, font=font1, relief='flat',
- bg='SystemButtonFace', highlightcolor='SystemButtonFace')
- l1.grid(row=2, column=1)
- def get_data(*args): # populate the Listbox with matching options
- search_str = e1.get() # user entered string
- l1.delete(0, END) # Delete all elements of Listbox
- for element in my_list:
- if re.match(search_str, element, re.IGNORECASE):
- l1.insert(tk.END, element) # add matching options to Listbox
- # l1.bind('<<ListboxSelect>>', my_upd)
- e1.bind('<Down>', my_down) # down arrow key is pressed
- l1.bind('<Right>', my_upd) # right arrow key is pressed
- l1.bind('<Return>', my_upd) # return key is pressed
- l1.bind("<ButtonPress-1>", my_upd) # return left-mouse clicked
- e1_str.trace('w', get_data) #
- # print(my_w['bg']) # reading background colour of window
- my_w.mainloop() # Keep the window open
- ###############################################################################
- from tkinter import *
- tray_window = None
- def loss_focus(event):
- print("loss_focus event")
- if tray_window is not None:
- if event.widget is not tray_window:
- tray_window.destroy()
- def show_tray_window(event):
- global tray_window
- #print("key up")
- if tray_window is None:
- tray_window = Toplevel(entry)
- x = entry.winfo_rootx() # Това е вградена функция
- y = entry.winfo_rooty() + entry.winfo_height() + 1
- tray_window.wm_overrideredirect(1)
- tray_window.wm_geometry("+%d+%d" % (x, y))
- label = Label(tray_window, text="Neshto", justify=LEFT,
- background="#ffffe0", relief=SOLID, borderwidth=1)
- label.pack()
- tray_window.bind('<FocusOut>', loss_focus)
- root = Tk()
- root.geometry("300x300")
- root.bind('<FocusOut>', loss_focus)
- entry = Entry(root)
- entry.bind('<Key>', show_tray_window)
- entry.pack()
- #tray_window = Toplevel(entry)
- root.mainloop()
- ################################################## https://www.youtube.com/watch?v=Bn1n1diGv_0
- from tkinter import *
- import pandas as pd
- from tkinter import ttk, filedialog
- root = Tk()
- root.title('Codemy.com - Excel To Treeview')
- root.iconbitmap('c:/gui/codemy.ico')
- root.geometry('700x500')
- # Create frame
- my_frame = Frame(root)
- my_frame.pack(pady=20)
- # Create treeview
- my_tree = ttk.Treeview(my_frame)
- # File open function
- def file_open():
- filename = filedialog.askopenfilename(
- initialdir="C:/gui/",
- title="Open A File",
- filetypes=(("xlsx files", "*.xlsx"), ("All Files", "*.*"))
- )
- if filename:
- try:
- filename = r"{}".format(filename)
- df = pd.read_excel(filename)
- except ValueError:
- my_label.config(text="File Couldn't Be Opened ...try again !")
- except FileNotFoundError:
- my_label.config(text="File Couldn't Be Opened ...try again !")
- # Clear old treeview
- clear_tree()
- # St up new treeview
- my_tree["column"] = list(df.colimns)
- my_tree["show"] = "headings"
- # Loop thru column list for headers
- for column in my_tree["column"]:
- my_tree.heading(column, text=column)
- # Put data in treview
- df_rows = df.to_numpy().tolist()
- for row in df_rows:
- my_tree.insert("", "end", values=row)
- # Pack the treeview finally
- my_tree.pack()
- def clear_tree():
- my_tree.delete(*my_tree.get_children())
- # Add a menu
- my_menu = Menu(root)
- root.config(menu=my_menu)
- # Add menu dropdown
- file_menu = Menu(my_menu, tearoff=False)
- my_menu.add_cascade(label="Spreadsheets", menu=file_menu)
- file_menu.add_command(label="Open", command=file_open)
- my_label = Label(root, text='')
- my_label.pack
- root.mainloop(pady=20)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement