Bottom Page

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)
#11
You should create minimal reproducible example. in Most cases you will find your error in the process...
Quote
#12
I don not know how to create a simpler one.

Actually, I appear to have enough space!
Full code

from tkinter import *
from tkinter import messagebox
from tkinter import filedialog
from tkinter.ttk import Button, Notebook
import os
import sys
import getpass
import smtplib
import webbrowser
import urllib.request

def AddCall():
    add()

def BackupCallSave():
    savefile()

def ViewCall():
    viewfile()

def PrintFileCall(): 
    printfile()

def ShareListCall():
    mailInstance = MailWin()

def SettingsInstance():
    settingsInstance = Settings()

def HTMLDataInstance():
    createData = HTMLRawData()

def SearchInstance():
    newSearch = SearchWin()

account = open("account.txt", "a+")
account.close()

login_details_user = open("loginuser.txt", "a+")
login_details_user.close()

login_details_user = open("loginuser.txt", "r")
check_char = login_details_user.read()
login_details_user.close()

login_details_passw = open("loginpassw.txt", "a+")
login_details_passw.close()

shop_name_details = open("shopnamecontainer.txt", "a+")
shop_name_details.close()

web_url = open("shopwebsite.txt", "a+")
web_url.close()

check_used = open("usedfiles.txt", "a+")
check_used.close()

save_file = open("saves.txt", "a+")
save_file.close()

if check_char == "":
    account = open("account.txt", "w")
    account.write("0")
    account.close()
    
window = Tk()
window.title("AutoOrder")    
#window.iconbitmap("feather.ico")
window.resizable(0, 0)

itemsvar = Variable(value = 1)
itembox = Entry(width = 50)
itemslist = Listbox(listvariable = itemsvar)
no_items_label = Label(text = "No products")
file = ""
session = 0 
no_items = True
used_file = False
shop_name = ""
validate_user = ""
validate_passw = ""
target_set = False
signed_in = False
file_was_viewed = False
url_set = False

account = open("account.txt", "r+")

status = account.read()

menubar = Menu()
menubar.add_command(label = "Add", state = DISABLED, command = AddCall)
menubar.add_command(label = "Backup", state = DISABLED, command = BackupCallSave)  
menubar.add_command(label = "Print", state = DISABLED, command = PrintFileCall)
menubar.add_command(label = "Email", state = DISABLED, command = ShareListCall)
menubar.add_command(label = "View", command = ViewCall)

def closeall():
    global signed_in
    if signed_in == False:
        try:
            sys.exit()
        except:
            raise SystemExit()
    else:
        exitq = messagebox.askquestion("Exit program", "Are you sure you want to exit AutoOrder?")
        if exitq == "yes":
            try:
                sys.exit()
            except:
                raise SystemExit()
        else:
            return

def error_handle():
    messagebox.showerror("An error occured", "An error occurred while setting the target file. Please set it again")
    file = ""
    
def spacer(linesno):
    for i in range(0, linesno):
        space = Label(text = "")
        space.pack()

def notebookspacer(linesno, tabmaster):
    for i in range(0, linesno):
        space = Label(tabmaster, text = "")
        space.pack()
 
def create_account_func():
    user = username.get()
    passw = password.get()
    if len(user and passw) == 0:
        messagebox.showerror("Fields missing", "Please fill out all required fields")
        pass
    else:
        if len(user and passw) < 10:
            messagebox.showerror("Username and password", "Username and password must be 10 characters or over")
        elif passw == shopNameSet.get() and len(passw and shopNameSet.get()) > 0:
            messagebox.showerror("Security", "For security, password must be different from shop name")
        else:
            shop_name_get = shopNameSet.get()
            shop_name_details = open("shopnamecontainer.txt", "w")
            shop_name_details.write(shop_name_get)
            shop_name_details.close()
            login_details_user = open("loginuser.txt", "w")
            login_details_user.write(user)
            login_details_user.close()
            login_details_passw = open("loginpassw.txt", "w")
            login_details_passw.write(passw)
            login_details_passw.close()
            messagebox.showinfo("Account created", "Your account was created")
            account.truncate(0)
            account.close()
            main_app()
            
def sign_in_func():
    user_contents = ask_user.get()
    passw_contents = ask_passw.get()
    if len(user_contents and passw_contents) == 0:
        messagebox.showerror("Fields missing", "Please fill out all fields")
        return
    else:
        login_details_user = open("loginuser.txt", "r")
        validate_user = login_details_user.read()
        login_details_user.close()
        login_details_passw = open("loginpassw.txt", "r")
        validate_passw = login_details_passw.read()
    if user_contents == validate_user and passw_contents == validate_passw:
        messagebox.showinfo("Logged in", "Welcome!")
        main_app()
    else:
        messagebox.showerror("Incorrect login", "Please try again")
        
if "0" in status:
    create_account = Label(text = "Create account", font = ("Segoe UI", 32))
    create_account.pack()
    spacer(3)
    username_label = Label(text = "Username")
    username_label.pack()
    spacer(1)
    username = Entry(width = 50)
    username.pack()
    spacer(3)
    password_label = Label(text = "Password")
    password_label.pack()
    spacer(1)
    password = Entry(width = 50, show = "\u2022")
    password.pack()
    spacer(1)
    shop_label = Label(text = "Name of shop or storeroom (optional)")
    shop_label.pack()
    spacer(1)
    shopNameSet = Entry(width = 50)
    shopNameSet.pack()
    spacer(1)
    create = Button(text = "Create account", width = 60, command = create_account_func)
    create.pack()
else:
    sign_in = Label(text = "Sign in", font = ("Segoe UI", 32))
    sign_in.pack()
    spacer(3)
    ask_username_label = Label(text = "Username")
    ask_username_label.pack()
    spacer(1)
    ask_user = Entry(width = 50)
    ask_user.pack()
    spacer(3)
    ask_password_label = Label(text = "Password")
    ask_password_label.pack()
    ask_passw = Entry(width = 50, show = "\u2022")
    ask_passw.pack()
    spacer(1)
    validation_system_activation = Button(text = "Sign in", width = 60, command = sign_in_func)
    validation_system_activation.pack()
    
def settarget():
    global file
    global target_set
    if file == "":
        messagebox.showinfo("Set target file", "Please select a file")
        window.filename = filedialog.askopenfilename(initialdir = "C:/Documents", title = "Set target file", filetypes = (("text files", ".txt"), ("all files","*.*")))
        file = window.filename
        letin = open(window.filename, "r")
        get_letters = letin.read()
        letin.close()
        check_used = open("usedfiles.txt", "r")
        check = check_used.read()
        if file in check and file != "":
            fileq = messagebox.askquestion("Clear data", "This file already has already been used with AutoOrder. Are you sure you want to clear it?", icon = "warning")
            if fileq == "yes":
                clearfile = open(window.filename, "w")
                clearfile.truncate(0)
                clearfile.close()
                check_used.close()
                menubar.entryconfigure(1, state = NORMAL)
                menubar.entryconfigure(2, state = NORMAL)
                menubar.entryconfigure(3, state = NORMAL)
                menubar.entryconfigure(4, state = NORMAL)
                target_set = True
                window.title("AutoOrder - " + window.filename)
            else:
                messagebox.showinfo("File was not used", "File was not cleared")
                check_used.close()
                file = ""
                window.filename = ""
        else:
            check_used.close()
            check_used = open("usedfiles.txt", "a")
            check_used.write(window.filename)        
            menubar.entryconfigure(1, state = NORMAL)
            menubar.entryconfigure(2, state = NORMAL)
            menubar.entryconfigure(3, state = NORMAL)
            menubar.entryconfigure(4, state = NORMAL)
            target_set = True
            window.title("AutoOrder - " + window.filename)
        if file != "":
            itembox.pack()
    else:
        messagebox.showerror("Could not set target file", "Cannot set target file or target file already set")           

class SearchWin:
    def searchList(self):
        content = self.searchTerms.get()
        next_index = 0
        elements = int(itembox.size())
        for i in range(0, elements):
            if content in itembox.get(next_index):
                itembox.activate(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()

def resetapp():
    setaccount = open("account.txt", "w")
    setaccount.write("0")
    setaccount.close()
    clearuser = open("loguser.txt", "w")
    clearuser.truncate(0)
    clearuser.close()
    clearpassw = open("loginpassw.txt", "w")
    clearpassw.truncate(0)
    clearpassw.close()
    clearshopname = open("shopnamecontainer.txt", "w")
    clearshopname.truncate(0)
    clearshopname.close()
    clearwebaddr = open("shopwebsite.txt", "w")
    clearwebaddr.truncate(0)
    clearwebaddr.close()
    clearsaves = open("saves.txt", "w")
    clearsaves.truncate(0)
    clearused = open("usedfiles.txt", "w")
    clearused.truncate(0)
    clearused.close()
    messagebox.showinfo("Exit", "Exit required to update")
    try:
        sys.exit()
    except:
        raise SystemExit()

class MailWin:
    def __init__(self):
        if self.check_connection() == True:
            defaultprovider = "smtp-mail.outlook.com"
            defaultport = 587
            self.provider = defaultprovider
            self.port = defaultport
            sendMail = Tk()
            sendMail.title("Email list")
            sendMail.iconbitmap("feather.ico")
            sendMail.resizable(0, 0)

            sendMailHeader = Label(sendMail, text = "Email list", font = ("Segoe UI", 32))
            sendMailHeader.pack()

            defaults = Label(sendMail, text = "Default provider: smtp-mail.outlook.com\nDefault port: 587")
            defaults.pack()

            Label(sendMail).pack()

            providerHeader = Label(sendMail, text = "Provider (optional)")
            providerHeader.pack()
            
            self.providerBox = Entry(sendMail, width = 50)
            self.providerBox.pack()

            Label(sendMail).pack()

            portHeader = Label(sendMail, text = "Port (optional)")
            portHeader.pack()

            self.portBox = Entry(sendMail, width = 50)
            self.portBox.pack()

            Label(sendMail).pack()

            mailRecLabel = Label(sendMail, text = "Recipient's email address")
            mailRecLabel.pack()

            self.recAddr = Entry(sendMail, width = 50)
            self.recAddr.pack()

            Label(sendMail).pack()

            mailUserLabel = Label(sendMail, text = "From email address")
            mailUserLabel.pack()

            self.mailUserBox = Entry(sendMail, width = 50)
            self.mailUserBox.pack()

            Label(sendMail).pack()

            mailPasswLabel = Label(sendMail, text = "From email password")
            mailPasswLabel.pack()

            self.mailPasswBox = Entry(sendMail, width = 50, show = "\u2022")
            self.mailPasswBox.pack()
            
            Label(sendMail).pack()

            sendBtn = Button(sendMail, text = "Send", width = 60, command = self.send)
            sendBtn.pack()
        else:
            messagebox.showerror("No internet", "Internet connection required. Try again later")
    
    def check_connection(self, host = "http://google.com"):
        try:
            urllib.request.urlopen(host)
            return True
        except:
            return False
    
    def send(self):
        global defaultprovider
        global defaultport
        if len(self.providerBox.get()) > 0:
            self.provider = providerBox.get()
            self.port = self.portBox.get()
        mail_user = self.mailUserBox.get()
        mail_passw = self.mailPasswBox.get()
        mailRecAddr = self.recAddr.get()
        if len(mail_user and mail_passw) > 0:
            try:
                get_list = open(window.filename, "r")
                listContent = get_list.read()
                get_list.close()
                server = smtplib.SMTP(self.provider, self.port)
                server.connect(self.provider, self.port)
                server.ehlo()
                server.starttls()
                server.ehlo()
                server.login(mail_user, mail_passw)
                server.sendmail(mail_user, mailRecAddr, "\n" + listContent)
                messagebox.showinfo("Sent", "Email sent\nProvider: " + self.provider + "\n" + "Port: " + str(self.port)) 
            except:
                messagebox.showerror("Invalid", "Invalid information")
        else:
            messagebox.showerror("Fields missing", "Please fill out all required fields")

def add_checker():
    if target_set == True:
        AddCall()
    else:
        messagebox.showerror("No target set", "Cannot add item to no target")

class HTMLRawData:
    def createHTML(self):
        HTMLRawData.path = self.filepath.get()
        class FileTest:
            @classmethod
            def __init__(cls):
                try:
                    test_path_file = open(HTMLRawData.path + ".txt", "a+")
                    test_path_file.close()
                    return True
                except:
                    messagebox.showerror("Invalid path", HTMLRawData.path + " is not a valid file path")
                    return False

        if FileTest.__init__() == True:
            path_file = open(HTMLRawData.path + ".txt", "a")
            path_file.write("<!DOCTYPE html>\n")
            path_file.write("<html>\n")
            path_file.write("<title>Raw data</title>")
            get_raw_data = open("saves.txt", "r")
            html_text = get_raw_data.read()
            get_raw_data.close()
            path_file.write("<h1>Raw data</h1>\n")
            path_file.write("<p>" + str(html_text) + "</p>\n")
            path_file.write("</html>\n")
            path_file.close()
            os.rename(HTMLRawData.path + ".txt", HTMLRawData.path + ".html")
            openwebsiteq = messagebox.askquestion("Complete", "Raw data in " + HTMLRawData.path + ".html" + "\nDo you want to open it?")
            if openwebsiteq == "yes":
                webbrowser.open(HTMLRawData.path + ".html")
            else:
                pass
        else:
            return

    def __init__(self):
        setupWebsite = Tk()
        setupWebsite.title("Setup HTML file name")
        setupWebsite.iconbitmap("feather.ico")
        setupWebsite.resizable(0, 0)
        
        Label(setupWebsite).pack()

        setupText = Label(setupWebsite, text = "HTML file name (to create)\nFull path required (without suffix)\nExample: C:/Users/username/Desktop/filename")
        setupText.pack(padx = 30)

        self.filepath = Entry(setupWebsite, width = 50)
        self.filepath.pack()

        Label(setupWebsite).pack()

        createHTMLbtn = Button(setupWebsite, text = "Create", command = self.createHTML)
        createHTMLbtn.pack()

        Label(setupWebsite).pack()

class Settings:
    @classmethod
    def openwebsite(cls):
        web_url = open("shopwebsite.txt", "r")
        get_addr = web_url.read()
        web_url.close()
        if len(get_addr) > 0:
            try:
                webbrowser.open(get_addr)
            except:
                messagebox.showerror("Invalid URL", get_addr + " is not a valid URL")
        else:
            messagebox.showerror("No URL set", "URL has not been set")

    def set_web_addr(self):
        global url_set
        web_addr = self.website.get()
        self.website.delete(0, "end")
        if len(web_addr) > 0:
            web_url = open("shopwebsite.txt", "w")
            web_url.truncate(0)
            web_url.write(web_addr)
            web_url.close()
            messagebox.showinfo("Web address set", "Shop web address set to: " + web_addr)
            url_set = True
            return
        else:
            messagebox.showerror("Enter web address", "Web address required")
            return

    def __init__(self):
        setup = Tk()
        setup.title("Settings")
        setup.attributes("-toolwindow", 1)
        setup.attributes("-topmost", 1)
        setup.resizable(0, 0)

        setupTabs = Notebook(setup)

        itemTab = Frame(setupTabs)
        launchTab = Frame(setupTabs)
        advancedTab = Frame(setupTabs)

        setupTabs.add(itemTab, text = "Products")
        setupTabs.add(launchTab, text = "Launch")
        setupTabs.add(advancedTab, text = "Advanced")

        itemsetup_label = Label(itemTab, text  = "Add item")
        itemsetup_label.pack()

        notebookspacer(1, itemTab)

        addbtn = Button(itemTab, text = "Add", command = add_checker)
        addbtn.pack()

        notebookspacer(1, itemTab)

        createHTMLbtn = Button(itemTab, text = "Copy raw data to HTML", command = HTMLDataInstance)
        createHTMLbtn.pack()

        notebookspacer(1, itemTab)

        url_label = Label(itemTab, text = "Shop website URL")
        url_label.pack()

        self.website = Entry(itemTab)
        self.website.pack()

        notebookspacer(1, itemTab)

        set_website = Button(itemTab, text = "Set website URL", command = self.set_web_addr)
        set_website.pack()

        launchlabel = Label(launchTab, text = "Launch setup")
        launchlabel.pack()

        notebookspacer(1, launchTab)  

        current_username = Label(launchTab, text = "Current user: " + getpass.getuser()) 
        current_username.pack()

        notebookspacer(2, launchTab)

        exitbtn = Button(launchTab, text = "Exit", command = closeall)
        exitbtn.pack()

        advancedlabel = Label(advancedTab, text = "Advanced setup")
        advancedlabel.pack()

        notebookspacer(1, advancedTab)

        resetbtn = Button(advancedTab, text = "Reset app", command = resetapp)
        resetbtn.pack()

        setupTabs.pack()   

def savefile():
    get_all_items = itemsvar.get()
    save_file = open("saves.txt", "r")
    letters = save_file.read()
    save_file.close()
    if len(letters) > 0:
        overq = messagebox.askquestion("Overwriting", "Are you sure you want to overwrite the existing backup file?")
        if overq == "yes":
            save_file = open("saves.txt", "w")
            save_file.truncate(0)
            save_file.write(str(get_all_items))
            save_file.close()
            messagebox.showinfo("Backed up", "Backup complete")
        else:
            messagebox.showinfo("Not overwitten", "Contents were kept")            
    else:
        save_file = open("saves.txt", "w")
        save_file.write(str(get_all_items))
        save_file.close()
        messagebox.showinfo("Backed up", "Backup complete")

def viewfile():
    file_was_viewed = True
    save_file = open("saves.txt", "r")
    insert_text = save_file.read()
    save_file.close()
    viewer = Tk()
    viewer.title("View backed up raw data")
    viewer.iconbitmap("feather.ico")
    viewer.resizable(0, 0)
    file_contents = Text(viewer)
    file_contents.config(state = NORMAL)
    file_contents.insert(INSERT, insert_text)
    file_contents.config(state = DISABLED)
    file_contents.pack()
    
def add():
    global session
    global no_items
    global itemslist
    itemname = itembox.get()
    if len(itemname) == 0:
        messagebox.showerror("Blank item", "Cannot add blank item")
    else:
        try:
            shop_name_details = open("shopnamecontainer.txt")
            name_of_shop = shop_name_details.read()
            shop_name_details.close()
            itemfile = open(window.filename, "a")
            session += 1
            if name_of_shop != "":
                itemfile.write(name_of_shop + ": " + "Product " + str(session) + ": " + itemname + "\n")
                itemfile.close()
            else:
                itemfile.write("Product " + str(session) + ": " + itemname + "\n")
                itemfile.close()
            itembox.delete(0, "end")
            messagebox.showinfo("Product added", "Product was added to " + window.filename + "\nProduct name: " + itemname)
            if no_items == True:
                no_items = False
                window.update()
                itembox.pack_forget()
                itemslist.pack()
                spacer(1)
                itembox_label = Label(text = "Product name")
                itembox_label.pack()
                spacer(1)
                itembox.pack()
                no_items_label.pack_forget()
            if name_of_shop != "":
                itemslist.insert(session, name_of_shop + ": " + "Product " + str(session) + ": " + itemname)      
            else:
                itemslist.insert(session, "Product " + str(session) + ": " + itemname)
        except:
            messagebox.showerror("Could not add", "Item could not be added to list")

def clear():
    global file   
    if file != "":
        itemfile = open(file, "r")
        readfile = itemfile.read()
        itemfile.close()
        if len(readfile) == 0:
            messagebox.showerror("Could not clear file", "File could not be cleared")
            return
    if file == "":
        settargetq = messagebox.askquestion("No target", "Please set a target. Would you like to set a target now?")
        if settargetq == "yes":
            settarget()
    else:
        clearq = messagebox.askquestion("Clear file", "Clear " + file + " and list?")
        if clearq == "yes":
            itemfile = open(window.filename, "w")
            itemfile.truncate(0)
            itemfile.close()
            itemslist.delete(0, END)
            messagebox.showinfo("Cleared", "File and list was cleared")
        else:
            pass
            
def printfile():
    global file
    itemfile = open(window.filename, "r")
    sourcecontent = itemfile.read()
    itemfile.close()
    if len(sourcecontent) > 0:
        printq = messagebox.askokcancel("Print?", "Will print to default printer") 
        if printq:
            try:
                os.startfile(file, "print")
            except:
                messagebox.showerror("Cannot print", "Could not print")
    else:
        messagebox.showerror("Cannot print", "Cannot print blank document")
        
def get_login():
    login_details_user = open("loginuser.txt", "r")
    get_username = login_details_user.read()
    login_details_user.close()
    login_details_passw = open("loginpassw.txt", "r")
    get_password = login_details_passw.read()
    login_details_passw.close()
    messagebox.showinfo("Login details", "Username: " + get_username + "\nPassword: " + get_password + "\nFor security, don't forget to close this message")
    
def main_app():
    global signed_in
    signed_in = True
    window.title("AutoOrder - No target")
    window.resizable(1, 1)
    if "0" in status:
        username.pack_forget()
        password.pack_forget()
        username_label.pack_forget()
        password_label.pack_forget()
        shop_label.pack_forget()
        shopNameSet.pack_forget()
        create_account.pack_forget()
        create.pack_forget()
    else:
        sign_in.pack_forget()
        ask_username_label.pack_forget()
        ask_user.pack_forget()
        ask_password_label.pack_forget()
        ask_passw.pack_forget()
        validation_system_activation.pack_forget()

    
    menubar.add_command(label = "Login", command = get_login)
    menubar.add_command(label = "Target", command = settarget)
    menubar.add_command(label = "Search", command = SearchInstance)
    menubar.add_command(label = "Settings", command = SettingsInstance)
    menubar.add_command(label = "Exit", command = closeall)
    
    spacer(1)
    
    items_list_label = Label(text = "Products", font = ("Segoe UI", 32))
    items_list_label.pack()
    
    spacer(1)
    
    no_items_label.pack()

    spacer(3)
    
    clearbtn = Button(text = "Clear", width = 10, command = clear)
    clearbtn.pack(pady = 30, side = BOTTOM)

    class OpenWebsiteBtn:
        def __init__(self):
            websitebtn = Button(text = "Open website", width = 20, command = Settings.openwebsite)
            websitebtn.pack(side = BOTTOM)
    
    show_btn = OpenWebsiteBtn()

    spacer(3)

    window.config(menu = menubar)

window.protocol("WM_DELETE_WINDOW", closeall)

window.mainloop()
Hope this is helpful!

The rest works fine!

Everything is important!
Quote
#13
You are referencing the wrong widget. If you had inserted a print command to display the type of itembox it would have printed <class 'tkinter.Entry'>. Entry .size() returns the dimensions of the widget. itemlist is a Listbox.
buran likes this post
Quote
#14
Thanks very much! I understand! Silly me!

Error:
File "c:\Users\joshu\Downloads\AutoOrderNew.py", line 267, in searchList if content in itembox.get(next_index): TypeError: get() takes 1 positional argument but 2 were given

itembox not itemslist, sorry!

What does this line do:
itemslist.activate(next_index)
Does this highlight a list item? Nothing happens when button pressed.
Quote
#15
(Mar-25-2020, 08:53 PM)chesschaser Wrote: Everything is important!

Actually, your original problem can be reproduced with 13 lines of code. At that point (and probably long before that) you would have spotted the problem.
from tkinter import *

class SearchWin:
    def searchList(self):
        elements = int(itembox.size())
             
    def __init__(self):
        self.searchPrompt = Tk()
        self.searchPrompt.geometry("150x150")
        searchbtn = Button(self.searchPrompt, text = "Search", command = self.searchList)
        searchbtn.pack()
 

s=SearchWin()
itembox = Entry(width = 50)
itemslist = Listbox(listvariable = itemsvar)
s.searchPrompt.mainloop()
Note, I used your original code with very small modifications. In any case you have big problem with overall structure of your code
Quote
#16
Yes, but what does this line do:
itemslist.activate(next_index)
Quote
#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)
Quote

Top Page

Forum Jump:


Users browsing this thread: 1 Guest(s)