Python Forum
List Comparing problem with GUI - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: List Comparing problem with GUI (/thread-29865.html)



List Comparing problem with GUI - ardvci - Sep-23-2020

Hello, I've been trying to compare two lists too see if one has substring
Let's say
AA=["Beautiful","Day"]
BB = ["Beau"]
I want to write a code that returns "Beautiful"
I find how to do that but it did not work with my gui
keywords = [] 
	def get():
    guess = Entry.get()
	keywords.append(guess)
	# print(keywords)
	global label3
	label3=tk.Label(lower_frame,text="İstediğiniz iletilmiştir",bg="#ECECF2")
	root.after(4000,label3.destroy)
	label3.pack()
	Entry.delete(0,tk.END)
	return keywords
this function gets the string from my entry box
def adana_web_scraping():
	source = requests.get("http://adana.gov.tr/duyurular").text
	soup = BeautifulSoup(source,'lxml')
	mydivs = soup.find('a',class_='announce-text')
	title = mydivs.text         
	x=title.split(' ')
	lists=x[32:]
	word=get()
	word=[x.lower() for x in word]
	a=[]
	lists=[x.lower() for x in lists]
	str1=" "
	C=[x for x in lists if any(b in x for b in word)]
	print(C)
and this function get the title of the first announcements on the website
but my C variable did not work. When I printed the C value it is the same with my lists variable.
So I wanted to compare the "lists" and "word" to see if the "word" list has a substring in the "lists"
Thanks for your helping


RE: List Comparing problem with GUI - Larz60+ - Sep-23-2020

to find a match, for each item in list BB, check item in list AA
if there is a match print AA value
>>> AA=["Beautiful","Day"]
>>> BB = ["Beau"] 
>>> 
>>> for bitem in BB:
...     for aitem in AA:
...         if bitem in aitem:
...             print(aitem)
... 
Beautiful



RE: List Comparing problem with GUI - ardvci - Sep-24-2020

Thanks for your contibution but unfortunately it did not work when I implemented to your code into mine.
I'll send the part of my code.
import tkinter as tk 
from googlesearch import search
from tkinter import messagebox
import webbrowser
from bs4 import BeautifulSoup
import requests
from PIL import Image, ImageTk
import time
import pandas as pd

keywords = []
def get():
	
	guess = Entry.get()
	keywords.append(guess)
	# print(keywords)
	global label3
	label3=tk.Label(lower_frame,text="İstediğiniz iletilmiştir",bg="#ECECF2")
	root.after(4000,label3.destroy)
	label3.pack()
	Entry.delete(0,tk.END)
	return keywords

def adana_web_scraping():
	source = requests.get("http://adana.gov.tr/duyurular").text
	soup = BeautifulSoup(source,'lxml')
	mydivs = soup.find('a',class_='announce-text')
	title = mydivs.text         
	x=title.split(' ')
	lists=x[32:]
	word=get()
	print(word)
	print(lists)
	word=[x.lower() for x in word]
	flag=0
	a=[]
	lists=[x.lower() for x in lists]
	str1=" "
	# str1.join(word)
	for bitem in word:
		for aitem in lists:
			if bitem in aitem:
				print(aitem)
				
root = tk.Tk()
root.wm_iconbitmap('eshid.ico')
root.wm_title('Title')
root.geometry("700x500")
root.title("EŞHİD GOOGLE TARAMA")
root.configure(bg="#E5E6E2")

img  = Image.open("D:\\Profile\\Desktop\\eshidd.png") 
photo=ImageTk.PhotoImage(img)
lab=tk.Label(image=photo).place(x=0,y=0)

label = tk.Label(root,text="Eşhid Google Tarama",bg="#E5E6E2",font=40)
label.pack()

Frame=tk.Frame(root,bg="#4784BC",bd=5)
Frame.place(relx=0.5,rely=0.1,relwidth=0.75,relheight=0.132,anchor="n")

Entry=tk.Entry(Frame,font=40,bd=4)
Entry.place(relwidth=0.5,relheight=0.5,relx=0.01)


Keyentry=tk.Entry(Frame,font=40,bd=4)
Keyentry.place(relx=0.01,rely=0.82,anchor="w",relwidth=0.50,relheight=0.50)

buttonstart = tk.Button(Frame,text="Kelimeleri Google'da Ara",font=40,command =lambda:searching_displaying_websites())
buttonstart.place(relx = 0.60,rely=0.27,anchor='w',relwidth=0.38,relheight=0.50)

Buttonstop=tk.Button(Frame,text="Yazdıklarını İlet",font=40,command=lambda:get())
Buttonstop.place(relx=0.60,rely=0.85,anchor="w",relwidth=0.38,relheight=0.50)


lower_frame=tk.Entry(root,bg="#ECECF2",bd=5)
lower_frame.place(relx=0.5,rely=0.4,relwidth=0.8,relheight=0.5,anchor="n")

my_menu=tk.Menu(root)
root.config(menu=my_menu)

website_menu=tk.Menu(my_menu)
my_menu.add_cascade(label="Valilik Web Scratching",menu=website_menu)
website_menu.add_command(label="Adana",command=lambda:adana_web_scraping())

root.mainloop()
To use the code use the first entry box the write your words and than click the "yazdıklarımı ilet" button.
this will get the keyword that you want to enter
After it compares the "lists" list you can see if you click on valilik web scratching then adana.
but somehow it did not compare them all it always returns the same variables in "lists" Could you please check that out.
Thanks for your help.


RE: List Comparing problem with GUI - Larz60+ - Sep-24-2020

My code is just an example, and I didn't expect that you would use verbatim in your code.


RE: List Comparing problem with GUI - ardvci - Sep-24-2020

Well, your code works fine actually but I still don't know why it does not work when I implemented.
Thanks for helping me.


RE: List Comparing problem with GUI - Larz60+ - Sep-25-2020

I will revisit tomorrow and take a closer look.