Reputation: 31
I posted the relevant code as well as the full traceback for the error. I have tried converting different elements to int, but none of that has worked. How can I fix this problem so that my code runs correctly and inserts data from the list into my listbox?
import typing
from typing import Text
import WearablesDataInterpreter
from WearablesDataInterpreter import *
import tkinter as tk
from tkinter import ALL, ANCHOR, Entry, Listbox
import PIL
from PIL import ImageTk
import tkmacosx
from tkmacosx import Button
from datetime import datetime
import sqlite3
import matplotlib.pyplot as plt
from matplotlib.patches import Patch
from matplotlib.lines import Line2D
import numpy as np
import sklearn
from sklearn.linear_model import LinearRegression
from sklearn import svm, metrics
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error
import math
from math import sqrt
def search_box_frame5(frame5):
def update(data):
input_list.delete(0, tk.END)
for item in data:
data.insert(tk.END, item)
def fillout(e):
user_input.delete(0, tk.END)
user_input.insert(0, input_list.get(ANCHOR))
def check(e):
typed = user_input.get()
if typed == '':
data = date_store
else :
data = []
for item in date_store:
if typed.lower() in item.lower():
data.append(item)
update(data)
date_store = [753, 756, 758, 761]
user_input = tk.Entry(frame5, width = 40)
user_input.pack()
input_list = Listbox(frame5, width = 40)
input_list.pack(pady=10)
update(date_store)
input_list.bind("<<ListboxSelect>>", fillout)
user_input.bind("<KeyRelease>", check)
ef load_frame5():
clear_widgets(frame1)
frame5.tkraise()
frame5.pack_propagate(False)
logo_img = ImageTk.PhotoImage(file = '/Users/piacobelli/Desktop/WearalesDataAnalyzer/ME Logo.png')
logo_widget = tk.Label(frame5, image = logo_img, bg = 'white')
logo_widget.image = logo_img
logo_widget.pack(pady=(10,0))
AccelerometerRegressionPlotMostRecent_widget = Button(frame5, bg = 'white', borderless = 1, text = "Accelerometer Regression Plot (Most Recent)", command = lambda: AccRegressionPlot())
AccelerometerRegressionPlotMostRecent_widget.pack(pady=(60, 20))
AccelerometerRegressionPlotOther_widget = Button(frame5, bg = 'white', borderless = 1, text = "Accelerometer Regression Plot (Other Timepoint)", command = lambda: search_box_frame5(frame5))
AccelerometerRegressionPlotOther_widget.pack(pady=20)
root = tk.Tk()
root.title('ML Analayzer')
root.eval('tk::PlaceWindow . center')
frame1 = tk.Frame(root, width = 520, height = 613, bg = bg_color)
frame2 = tk.Frame(root, width = 520, height = 613, bg = bg_color)
frame3 = tk.Frame(root, width = 520, height = 613, bg = bg_color)
frame4 = tk.Frame(root, width = 520, height = 613, bg = bg_color)
frame5 = tk.Frame(root, width = 520, height = 613, bg = bg_color)
load_frame1()
root.mainloop()
Full Traceback:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/tkinter/__init__.py", line 1921, in __call__
return self.func(*args)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/tkmacosx/basewidgets/button_base.py", line 893, in cmd
self.cnf['command']()
File "/Users/piacobelli/Desktop/WearalesDataAnalyzer/MLDataAnalyzer.py", line 241, in <lambda>
AccelerometerRegressionPlotOther_widget = Button(frame5, bg = 'white', borderless = 1, text = "Accelerometer Regression Plot (Other Timepoint)", command = lambda: search_box_frame5(frame5))
File "/Users/piacobelli/Desktop/WearalesDataAnalyzer/MLDataAnalyzer.py", line 73, in search_box_frame5
update(date_store)
File "/Users/piacobelli/Desktop/WearalesDataAnalyzer/MLDataAnalyzer.py", line 48, in update
data.insert(tk.END, item)
TypeError: 'str' object cannot be interpreted as an integer
Upvotes: 0
Views: 245
Reputation: 633
In line 48, you probably meant to write input_list.insert(tk.END, item)
data
is a list, its method .insert
doesn't work with tk.END
(which is the string 'end')
input_list
is instead a tkinter.Listbox
and its .insert
does perfectly fine with it
Upvotes: 2