Python Forum
Test program returns int (I want int) and real one returns tuple (not wanted)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Test program returns int (I want int) and real one returns tuple (not wanted)
#17
WooHoo! The code partially works!

class SearchWin:
    def searchList(self):
        content = self.searchTerms.get()
        next_index = 0
        elements = int(itemslist.size())
        for i in range(0, elements):
            if content in itemslist.get(next_index):
                itemslist.select_set(next_index)
                break
            else:
                if next_index <= elements:
                    next_index += 1
                    continue
                else:
                    messagebox.showerror("Item not found", "No item could be found containing " + "'" + content + "'")
            
    def __init__(self):
        searchPrompt = Tk()
        searchPrompt.title("Search list")
        #searchPrompt.iconbitmap("feather.ico")
        searchPrompt.resizable(0, 0)

        searchText = Label(searchPrompt, text = "Search terms")
        searchText.pack()

        Label(searchPrompt).pack()

        self.searchTerms = Entry(searchPrompt, width = 30)
        self.searchTerms.pack(padx = 10)

        Label(searchPrompt).pack()

        searchbtn = Button(searchPrompt, text = "Search", command = self.searchList)
        searchbtn.pack()
Glitches:

1. Messagebox not displayed (line 15) when item not found
2. Not all items that contain the search term are highlighted

3. Forgot. Item 3 highlights item 1 (not sure)
Reply


Messages In This Thread
RE: Test program returns int (I want int) and real one returns tuple (not wanted) - by chesschaser - Mar-26-2020, 11:26 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Entry returns NONE mollerpunker 2 2,533 Dec-06-2020, 06:50 PM
Last Post: DT2000

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020