[Tutor] getting back my listbox items

2018-06-24 Thread Ali M
Hi, when i do search in my Entrybox the list lowers down to that typed item
the code of which i wrote in the update_list function. how should i get
listbox items back again after it has been lowered? and another question:
if i want to format some specific text in my Text widget i should use
BeautifulSoup or can i do that with add_tag method? i used add_tag method
in my enter_meaning function but it formats the first 4 letters of anyword,
but i want the words which are in the listofwords to be formatted.


import sqlite3 as sqlite
import tkinter as tk
from tkinter import ttk
#GUI Widgets


class EsperantoDict:
def __init__(self, master):

master.title("EsperantoDict")
master.iconbitmap("Esperanto.ico")
master.resizable(False, False)
master.configure(background='#EAFFCD')
self.style = ttk.Style()
self.search_var = tk.StringVar()
self.search_var.trace("w", lambda name, index, mode:
self.update_list())

self.style = ttk.Style()
self.style.configure("TFrame", background='#EAFFCD')
self.style.configure("TButton", background='#C6FF02')
self.style.configure("TLabel", background='#EAFFCD')

self.frame_header = ttk.Frame(master, relief=tk.FLAT)
self.frame_header.config(style="TFrame")
self.frame_header.pack(side=tk.TOP, padx=5, pady=5)

self.logo = tk.PhotoImage(file=r'C:\EsperantoDict\eo.png')
self.small_logo = self.logo.subsample(10, 10)

ttk.Label(self.frame_header, image=self.small_logo).grid(row=0,
column=0, stick="ne", padx=5, pady=5, rowspan=2)
ttk.Label(self.frame_header, text='EsperantoDict', font=('Arial',
18, 'bold')).grid(row=0, column=1)

self.frame_content = ttk.Frame(master)
self.frame_content.config(style="TFrame")
self.frame_content.pack()

self.entry_search = ttk.Entry(self.frame_content,
textvariable=self.search_var, width=30)
self.entry_search.bind('', self.entry_delete)
self.entry_search.bind('', self.entry_insert)
self.entry_search.grid(row=0, column=0, padx=5)
self.entry_search.focus()

self.button_search = ttk.Button(self.frame_content, text="Search")
self.photo_search =
tk.PhotoImage(file=r'C:\EsperantoDict\search.png')
self.small_photo_search = self.photo_search.subsample(3, 3)
self.button_search.config(image=self.small_photo_search,
compound=tk.LEFT, style="TButton")
self.button_search.grid(row=0, column=2, columnspan=1, sticky='nw',
padx=5)

self.listbox = tk.Listbox(self.frame_content, height=30, width=30)
self.listbox.grid(row=1, column=0, padx=5)
self.scrollbar = ttk.Scrollbar(self.frame_content,
orient=tk.VERTICAL, command=self.listbox.yview)
self.scrollbar.grid(row=1, column=1, sticky='nsw')
self.listbox.config(yscrollcommand=self.scrollbar.set)
self.listbox.bind('<>', self.enter_meaning)

self.textbox = tk.Text(self.frame_content, relief=tk.GROOVE,
width=60, height=30, borderwidth=2)
self.textbox.config(wrap='word')
self.textbox.grid(row=1, column=2, sticky='w', padx=5)

# SQLite
self.db = sqlite.connect(r'C:\EsperantoDict\test.db')
self.cur = self.db.cursor()
self.cur.execute('SELECT Esperanto FROM Words')
for row in self.cur:
self.listbox.insert(tk.END, row)
for row in range(0, self.listbox.size(), 2):
self.listbox.itemconfigure(row, background="#f0f0ff")

def update_list(self):
search_term = self.search_var.get()
for item in self.listbox.get(0, tk.END):
if search_term.lower() in item:
self.listbox.delete(0, tk.END)
self.listbox.insert(tk.END, item)

# SQLite
def enter_meaning(self, tag):
for index in self.listbox.curselection():
esperanto = self.listbox.get(index)
results = self.cur.execute("SELECT English FROM Words WHERE
Esperanto = ?", (esperanto))
for row in results:
self.textbox.delete(1.0, tk.END)
self.textbox.insert(tk.END, row)
listofwords = ("gram", "med")
self.textbox.tag_add('listofwords', '1.0', '1.4')
self.textbox.tag_configure('listofwords',
background='yellow', font='helvetica 14 bold', relief='raised')

def entry_delete(self, tag):
self.entry_search.delete(0, tk.END)
return None

def entry_insert(self, tag):
self.entry_search.delete(0, tk.END)
self.entry_search.insert(0, "Type to Search")
return None


def main():
root = tk.Tk()
esperantodict = EsperantoDict(root)
root.mainloop()


if __name__ == '__main__': main()

# db tbl name: Words
# db first field name: Esperanto
# db second field name: English
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription opti

[Tutor] egg timer

2018-06-24 Thread Paula Malimba
Hello,

I'm new to programming and am studying the book Begin to Code with Python.
I'm stuck in lesson 3, trying to make an egg timer. I keep having a syntax
error.

Please help!!!

Thanks,
Paula
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] egg timer

2018-06-24 Thread Alan Gauld via Tutor
On 24/06/18 22:21, Paula Malimba wrote:

> I'm new to programming and am studying the book Begin to Code with Python.
> I'm stuck in lesson 3, trying to make an egg timer. I keep having a syntax
> error.

Most of us won't have that book and so can't see the code.

More importantly none of us can see *your* code.
Please always cut n' paste your code into the emails.
(please, don't use attachments because they often get
stripped by the mail server as a security risk.)

Also the error message, from where it says Traceback to
the end. It may look like gobbledegook to you but it
does actually have a lot of useful information that
can help us see what went wrong.

Without those two things we are pretty much unable
to help, so please repost with the missing info.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] egg timer

2018-06-24 Thread boB Stepp
Greetings, Paula!

On Sun, Jun 24, 2018 at 4:52 PM Paula Malimba  wrote:
>
> Hello,
>
> I'm new to programming and am studying the book Begin to Code with Python.
> I'm stuck in lesson 3, trying to make an egg timer. I keep having a syntax
> error.
>
> Please help!!!

Please pretend for a moment that you received your own email above.
Read it carefully.  If you were trying to help this person, "Paula",
how would you answer the following questions?

1)  Hmm.  She is having a syntax error.  This could be one of a large
number of possible syntax errors, each having a different cause.
Which syntax error might she be having?

2)  She is doing lesson 3 from the book "Begin to Code with Python".
I don't own that particular book.  I wonder what that lesson is about
and what specific problem(s) she is trying to solve?

3)  How is she running her program?  Is she running it directly from
the Python terminal?  From a ".py" file?

4)  I wonder what version of Python she is running?  Python 2.X or
3.X?  This might make a difference in how I answer her.

5)  And what operating system is she using?  This could be a factor, too.

Paula, I am *not* trying to be condescending!  But your email as sent
is so vague I (and everyone else) has no idea how to help you.  As an
example of the kind of information we need, I artificially generated a
syntax error of my own.  If I were asking for help I would probably
say something like the following:

Hi folks!  I am working on an egg timer challenge from the book "Begin
to Code with Python".  In lesson 3 it asks me to query the user to
enter how many minutes he/she wants his/her egg boiled.  I wrote the
following code in my Python interpreter:

py3: time = input("Please tell me how many minutes you want your egg to boil?)

, but I got the following error:

File "", line 1
time = input("Please tell me how many minutes you want your egg to boil?)
^
SyntaxError: EOL while scanning string literal

I am using Python 3.6.5 on Windows 7-64 bit.  I was trying to get the
amount of time in minutes the user wanted me to boil the egg in my
"time" variable, but I got the above error.  What am I doing wrong?

Do you think you might be able to answer my question?

Hope this helps us to help you, and we really do want to help!

Cheers!




-- 
boB
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] getting back my listbox items

2018-06-24 Thread Alan Gauld via Tutor
On 24/06/18 18:26, Ali M wrote:

Just a quick observation, its too late to read it in detail...

> def update_list(self):
> search_term = self.search_var.get()
> for item in self.listbox.get(0, tk.END):
> if search_term.lower() in item:
> self.listbox.delete(0, tk.END)
> self.listbox.insert(tk.END, item)

This function deletes the entire list if the search
term is included in the item. It does this every time.
So any items inserted at the end in earlier iterations
will be deleted by later finds.

Is that really what you want?

> def entry_delete(self, tag):
> self.entry_search.delete(0, tk.END)
> return None

Why do you have tag as a parameter when you don't use it?

> def entry_insert(self, tag):
> self.entry_search.delete(0, tk.END)
> self.entry_search.insert(0, "Type to Search")
> return None

same here?

G'night. :-)

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor