mercredi 9 août 2017

inserting a checkbox into a text box, python 3.6

As the title says I need a checkbox inserted into a text box for each line the program returns when searching a csv file and I need to have the user be able to click the box they want and click a button that gets just the lines that are checked. I have tried and searched ALOT of different ways I could think of and nothing is working. Any help is greatly appreciated!

The following code is just an example with the same effect.

import tkinter as tk
from tkinter import ttk 
self = tk.Tk()
def TOGGLESEARCH(op_menu):
    DATAF = var.get()
    if DATAF == "EXAMPLE 1":
        BASEF = "one.csv"
    if DATAF == "EXAMPLE 2":
        BASEF = "two.csv"
    def UPC_SEARCH():
        with open(BASEF, 'r') as f:
            search_f = f.readlines()
            text_box = tk.Text(self, width = 90, height = 6)
            text_box.grid(row = 3, column = 3, sticky = "ew", pady = (0,0), padx = (20,0))
            ScrollBar = tk.Scrollbar(self)
            ScrollBar.config(command = text_box.yview)
            text_box.config(yscrollcommand = ScrollBar.set)
            ScrollBar.grid(row = 3, column = 4, sticky = "ns")
            text_box.delete(1.0, "end-1c")
            USER_TEXT = UPC_Search_Entry.get()  
            if USER_TEXT == '':
                text_box.config(foreground = 'red', font = ("Helvetica", 12))
                text_box.insert(tk.END, "PLEASE ENTER A VALUE")
            else:
                match_in_file = False
                for line in search_f:
                    if USER_TEXT in line:
                        text_box.config(foreground = 'black', wrap = tk.WORD, font = ("Helvetica", 12))
                        text_box.insert(tk.END, "{}".format(line))
                        match_in_file = True
                if match_in_file == False:
                    text_box.config(foreground = 'red', font = ("Helvetica", 12))
                    text_box.insert(tk.END, "INVENTORY DOES NOT EXIST")
            text_box.configure(state = 'disabled')  # << this is here because its a huge part of my main script and needs to stay if it can 
    UPC_Search_label = tk.Label(self, text = "Search Inventory", font = ("Helvetica",14))
    UPC_Search_label.grid(row = 2, column = 1, sticky = "nsew")
    UPC_Search_Entry = tk.Entry(self)
    UPC_Search_Entry.config(font = ("Helvetica", 12))
    UPC_Search_Entry.grid(row = 3, column = 1, sticky = "nsew", pady = 0, padx = 2)
    UPC_SEARCH_BUTTON = ttk.Button(self, text = "Search", command = lambda: UPC_SEARCH())
    UPC_SEARCH_BUTTON.grid(row = 3, column = 2, sticky = "nsew")
var = tk.StringVar()
var.set("Select Option")
op_menu = tk.OptionMenu(self, var, "EXAMPLE 1", "EXAMPLE 2", command = TOGGLESEARCH)
op_menu.grid(row = 1, column = 1)
op_menu.config(width = 15, foreground = 'dark green', font = ("Helvetica", 12, "bold"))
app = self
app.mainloop()

For the csv files just throw anything together that has at least 4 values cause that's what my main program uses. Also this is the checkbox I want

var1 = tk.IntVar()
TEST = tk.Checkbutton(self, variable = var1)




Aucun commentaire:

Enregistrer un commentaire