As i have set search term to global for the first function - shouldnt the second function be able to access it - if not how would i get this to work?
import sys
import os.path
from tkinter import *
import math
def setupsearch():
exist = os.path.isfile('messages.txt')
if exist == True:
global searchterm
gui2 = Toplevel(master=gui)
Label(gui2, text = "Search Term").grid(row = 0)
searchterm = Entry(gui2).grid(row = 1)
Button(gui2, text="Search", command = search).grid(row = 2)
else:
labelprint = "No Stored Messages"
add = Label(gui, text = labelprint, width = 30)
add.grid(row = 2, column =2)
def search():
searchterm =
with open('messages.txt', 'r') as inF:
i = 1
for line in inF:
if searchterm in line:
print("found it in line " + str(i))
i = i + 1
else:
print("Not in line " + str(i))
i = i + 1
gui = Tk()
Button(gui, text="Retriever", command=setupsearch).grid(row = 5, column = 0)
mainloop( )