Hello everyone on the internet! I am making a stock prediction model in python
and tkinter
but I have trouble with No responding Python
when I try to search ‘a’ on on the combo box widget
. The combobox
has an autofill function and it contains a list of names of stocks the list size is 3971 lines long. No response python
here is my code:
<code># import gui
import tkinter as tk
from tkinter import ttk
import pandas as pd
def start_win():
# create instance
win = tk.Tk()
# title name
win.title("test")
# resizable option
win.resizable(True, True)
# window size
win.geometry("375x315")
top_frame = ttk.LabelFrame(win, text='')
top_frame.grid(column=0, row=0, padx=10, pady=10)
# import csv
csv = pd.read_csv('stocks.csv')
stock_names = csv['Name'].tolist()
stock_names.append('Other')
ttk.Label(top_frame, text='Search Stocks: ').grid(column=0, row=0)
# combo box
stocks_var = tk.StringVar()
stocks = ttk.Combobox(top_frame, width=10, textvariable=stocks_var)
stocks['values'] = stock_names
#stocks['values'] = ('other')
stocks.grid(column=1, row=0)
stocks.current(0)
def search(e):
value = stocks.get()
print(value)
if value == '':
stocks['values'] = stock_names
else:
data = []
for i in stock_names:
if value.lower() in i.lower():
data.append(i)
stocks['values'] = data
win.bind('<KeyRelease>', search)
# start GUI
win.mainloop()
#sub button func
def sub_button_func():
sub.quit()
sub.destroy()
start_win()
exit()
#sub button
sub_button = ttk.Button(sub, text='OK', command=sub_button_func)
sub_button.grid(column=0, row=2)
sub.mainloop()
</code>
<code># import gui
import tkinter as tk
from tkinter import ttk
import pandas as pd
def start_win():
# create instance
win = tk.Tk()
# title name
win.title("test")
# resizable option
win.resizable(True, True)
# window size
win.geometry("375x315")
top_frame = ttk.LabelFrame(win, text='')
top_frame.grid(column=0, row=0, padx=10, pady=10)
# import csv
csv = pd.read_csv('stocks.csv')
stock_names = csv['Name'].tolist()
stock_names.append('Other')
ttk.Label(top_frame, text='Search Stocks: ').grid(column=0, row=0)
# combo box
stocks_var = tk.StringVar()
stocks = ttk.Combobox(top_frame, width=10, textvariable=stocks_var)
stocks['values'] = stock_names
#stocks['values'] = ('other')
stocks.grid(column=1, row=0)
stocks.current(0)
def search(e):
value = stocks.get()
print(value)
if value == '':
stocks['values'] = stock_names
else:
data = []
for i in stock_names:
if value.lower() in i.lower():
data.append(i)
stocks['values'] = data
win.bind('<KeyRelease>', search)
# start GUI
win.mainloop()
#sub button func
def sub_button_func():
sub.quit()
sub.destroy()
start_win()
exit()
#sub button
sub_button = ttk.Button(sub, text='OK', command=sub_button_func)
sub_button.grid(column=0, row=2)
sub.mainloop()
</code>
# import gui
import tkinter as tk
from tkinter import ttk
import pandas as pd
def start_win():
# create instance
win = tk.Tk()
# title name
win.title("test")
# resizable option
win.resizable(True, True)
# window size
win.geometry("375x315")
top_frame = ttk.LabelFrame(win, text='')
top_frame.grid(column=0, row=0, padx=10, pady=10)
# import csv
csv = pd.read_csv('stocks.csv')
stock_names = csv['Name'].tolist()
stock_names.append('Other')
ttk.Label(top_frame, text='Search Stocks: ').grid(column=0, row=0)
# combo box
stocks_var = tk.StringVar()
stocks = ttk.Combobox(top_frame, width=10, textvariable=stocks_var)
stocks['values'] = stock_names
#stocks['values'] = ('other')
stocks.grid(column=1, row=0)
stocks.current(0)
def search(e):
value = stocks.get()
print(value)
if value == '':
stocks['values'] = stock_names
else:
data = []
for i in stock_names:
if value.lower() in i.lower():
data.append(i)
stocks['values'] = data
win.bind('<KeyRelease>', search)
# start GUI
win.mainloop()
#sub button func
def sub_button_func():
sub.quit()
sub.destroy()
start_win()
exit()
#sub button
sub_button = ttk.Button(sub, text='OK', command=sub_button_func)
sub_button.grid(column=0, row=2)
sub.mainloop()
I think the problem of it is because of the large list and I think it can be solved by numpy
Thank you for your help!