[Tutor] I get an error while search in my Entry field

2018-06-18 Thread Ali M
Hi, i get an error while searching my Entry field and i don't understand
what that means.

code:

#! /usr/bin/env python3
#GeologyDict by Ali M
import sqlite3 as sqlite
import tkinter as tk
from tkinter import Text
from tkinter import Entry
from tkinter import Scrollbar
from tkinter import ttk

#GUI Widgets


class EsperantoDict:
def __init__(self, master):

master.title("EsperantoDict")
master.resizable(False, False)
master.configure(background='#EAFFCD')

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='#EAFFCD')
self.style.configure("TLabel", background='#EAFFCD')

self.frame_header = ttk.Frame(master, relief=tk.FLAT)
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.pack()

self.entry_search = ttk.Entry(self.frame_content,
textvariable=self.search_var)
self.entry_search.grid(row=0, column=0)
self.entry_search.bind('', self.entry_delete)

self.button_search = ttk.Button(self.frame_content, text="Search")
self.aks = tk.PhotoImage(file=r'C:\EsperantoDict\search.png')
self.small_aks = self.aks.subsample(3, 3)
self.button_search.config(image=self.small_aks, compound=tk.LEFT)
self.button_search.grid(row=0, column=1, columnspan=2)

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

self.textbox = tk.Text(self.frame_content, width=60, height=27)
self.textbox.grid(row=1, column=2)

# 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)
# SQLite

def enter_meaning(self, tag):
if self.listbox.curselection():
results = self.cur.execute("SELECT English FROM Words WHERE
rowID = 1")
for row in results:
self.textbox.insert(tk.END, row)

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

def entry_delete(self, tag):
self.entry_search.delete(0, tk.END)
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

error:
Exception in Tkinter callback
Traceback (most recent call last):
  File
"C:\Users\deadmarshal\AppData\Local\Programs\Python\Python36\lib\tkinter\__init__.py",
line 1702, in __call__
return self.func(*args)
  File "C:/EsperantoDict/EsperantoDict.py", line 21, in 
self.search_var.trace("w", lambda name, index, mode: self.update_list())
  File "C:/EsperantoDict/EsperantoDict.py", line 77, in update_list
for item in self.listbox:
  File
"C:\Users\deadmarshal\AppData\Local\Programs\Python\Python36\lib\tkinter\__init__.py",
line 1486, in cget
return self.tk.call(self._w, 'cget', '-' + key)
TypeError: must be str, not int
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[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] putting accent on letters while user is typing in Entrybox (Tkinter)

2018-07-15 Thread Ali M
Hi. I want to write these (ĝ, ĉ, ĵ, ĥ, ŭ, ĉ) accented letters when the user
types (gx, cx, jx, ux, cx).

when user types 'gx' for example i want to remove that x and replace it
with the accent. how should i do that? and how should i specify which
accent goes above which letter? thanks.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] putting accent on letters while user is typing in Entrybox (Tkinter)

2018-07-16 Thread Ali M
The accents which i want to be automatically converted and put upon letters
is circumflex and another one which shape is like the opposite of
circumflex.

the user types in entrybox and it searches in db which i've created before
and has no problem. the words in my db have unicode characters and they are
accented. the user himself can type accented characters too, but i want to
make it automatically converted so the user doesn't have to have a special
keyboard to write.

when x is pressed after these letters (g,j,c,h,u), i want that x to be
removed and replaced with a circumflex above those letters.

here is the full code if needed:

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")
self.update_list()

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)

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()
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Getting current listbox item index and bind it to button (Tkinter)

2018-08-02 Thread Ali M
Hi, in my code i have the curselection in my enter_meaning function, and it
works well and prints the result which comes from db to the text widget.
When user searches in entrybox the list lowers down to 1 item, how can i
get the index of that item and bind it to the button so it will print the
result like curselection does but with pressing the Enter key on keyboard?
I tried writing the search_word function and binded it to the button, but
it doesn't work, please help i'm still a beginner.

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.entry_search.bind("", self.edit_input)

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.button_search.bind('', self.search_word)

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 ORDER BY Esperanto")
for row in self.cur:
self.listbox.insert(tk.END, row)
self.update_list()

def update_list(self):
self.listbox.delete(0, tk.END)
search_term = self.search_var.get().lower()
if search_term == 'type to search':
search_term = ''
self.cur.execute("SELECT Esperanto FROM Words WHERE
LOWER(Esperanto) LIKE ? ORDER BY Esperanto",
('%'+search_term+'%',))
for row in self.cur:
item = row[0]
self.listbox.insert(tk.END, item)
for row in range(0, self.listbox.size(), 2):
self.listbox.itemconfigure(row, background="#f0f0ff")

def edit_input(self, tag):
word_to_esp = {'gx': 'ĝ', 'cx': 'ĉ', 'hx': 'ĥ', 'jx': 'ĵ', 'ux':
'ŭ', 'sx': 'ŝ'}
user_input = self.entry_search.get()
user_input = user_input.lower()
for i in word_to_esp:
if user_input.__contains__(i):
a = user_input.replace(i, word_to_esp[i])
return self.search_var.set(a)

# 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[0])

def entry_delete(self, tag):
if self.entry_search.get():
self.entry_search.delete(0, tk.END)
s

[Tutor] Getting current listbox item index and bind it to button (Tkinter)

2018-08-04 Thread Ali M
I have taken the delete statement out of the for loop, but still nothing
happens when i click the button. i want that button to take the current
list item index and do what the curselection does (which is printing the
result in text widget).

import sqlite3 as sqlite
import tkinter as tk
from tkinter import ttk


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.entry_search.bind("", self.edit_input)

self.button_search = ttk.Button(self.frame_content, text=u"Serĉu")
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.button_search.bind('', self.enter_meaning)

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 ORDER BY Esperanto")
for row in self.cur:
self.listbox.insert(tk.END, row)
self.update_list()

def update_list(self):
self.listbox.delete(0, tk.END)
search_term = self.search_var.get().lower()
if search_term == 'type to search':
search_term = ''
self.cur.execute("SELECT Esperanto FROM Words WHERE
LOWER(Esperanto) LIKE ? ORDER BY Esperanto",
 ('%' + search_term + '%',))
for row in self.cur:
item = row[0]
self.listbox.insert(tk.END, item)
for row in range(0, self.listbox.size(), 2):
self.listbox.itemconfigure(row, background="#f0f0ff")

def edit_input(self, tag):
word_to_esp = {'gx': 'ĝ', 'cx': 'ĉ', 'hx': 'ĥ', 'jx': 'ĵ', 'ux':
'ŭ', 'sx': 'ŝ'}
user_input = self.entry_search.get()
user_input = user_input.lower()
for i in word_to_esp:
if user_input.__contains__(i):
a = user_input.replace(i, word_to_esp[i])
return self.search_var.set(a)

# SQLite
def enter_meaning(self, tag):
for index in self.listbox.curselection():
esperanto = self.listbox.get(index)
global results
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[0])

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

def entry_insert(self, tag):
if self.entry_search.get() == '':
self.entry_search.insert(0, "Type to Search")
return None

def search_word(

[Tutor] Getting current listbox item index and bind it to button (Tkinter)

2018-08-07 Thread Ali M
If i delete this line "self.textbox.delete(1.0, tk.END)" in my
enter_meaning function the listbox items won't lower down to 1 item and i
just want 1 item to be shown after user searches the item in entrybox.
what i want to do is: when user searches in entrybox, the listbox items
lowers down to that searched item only, and when i click on that 1
remaining item, the results from db prints in text widget, i want to be
able to also use the button to print it. how can i configure the button for
this? i hope i explained clearly.

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.entry_search.bind("", self.edit_input)

self.button_search = ttk.Button(self.frame_content, text=u"Serĉu")
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.button_search.bind('', self.search_word)

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 ORDER BY Esperanto")
for row in self.cur:
self.listbox.insert(tk.END, row)
self.update_list()

def update_list(self):
self.listbox.delete(0, tk.END)
search_term = self.search_var.get().lower()
if search_term == 'type to search':
search_term = ''
self.cur.execute("SELECT Esperanto FROM Words WHERE
LOWER(Esperanto) LIKE ? ORDER BY Esperanto",
 ('%' + search_term + '%',))
for row in self.cur:
item = row[0]
self.listbox.insert(tk.END, item)
for row in range(0, self.listbox.size(), 2):
self.listbox.itemconfigure(row, background="#f0f0ff")

def edit_input(self, tag):
word_to_esp = {'gx': 'ĝ', 'cx': 'ĉ', 'hx': 'ĥ', 'jx': 'ĵ', 'ux':
'ŭ', 'sx': 'ŝ'}
user_input = self.entry_search.get()
user_input = user_input.lower()
for i in word_to_esp:
if user_input.__contains__(i):
a = user_input.replace(i, word_to_esp[i])
return self.search_var.set(a)

# SQLite
def enter_meaning(self, tag):
for index in self.listbox.curselection():
global esperanto
global results
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[0])

def entry_delete(self, t

[Tutor] Encrypting shipped sqlite db in app directory

2019-03-29 Thread Ali M
I want to encrypt my sqlite databases which are shipped with the app in
it's directory, so that the user can't modify or use it elsewhere, and they
will only be accessible for the app to read from, how can i do that?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] What is the correct way of signalling and slots in PyQt5?

2019-04-03 Thread Ali M
The application crashes without errors every time any signal is called on
the widgets. how should i signal to my functions?
for example these signals make the app crash:
self.lineEdit.textChanged.connect(self.edit_input)
or
self.listWidget.clicked.connect(self.listClicked)

here is the full code:
from PyQt5 import QtCore, QtGui, QtWidgets
import sqlite3 as sqlite
import sys

class Ui_MainWindow(object):
def setupUi(self, MainWindow):
super().__init__()
self.initUi()

def initUi(self):

self.centralwidget = QtWidgets.QWidget(MainWindow)

self.lineEdit = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit.textChanged.connect(self.edit_input)

self.listWidget = QtWidgets.QListWidget(self.centralwidget)
self.listWidget.clicked.connect(self.listClicked)

self.textEdit = QtWidgets.QTextEdit(self.centralwidget)

MainWindow.setCentralWidget(self.centralwidget)

self.db =
sqlite.connect(r'C:\Users\deadmarshal\PycharmProjects\Tim\test.db')
self.cur = self.db.cursor()
self.result = self.cur.execute("SELECT Esperanto FROM Words ORDER
BY Esperanto")
self.items = self.result.fetchall()

for i in self.items:
self.listWidget.insertItems(0, i)

def listClicked(self):
index = self.listWidget.currentRow()
results = self.cur.execute("SELECT English FROM Words WHERE
Esperanto = ?", (index,))
for row in results:
self.textEdit.clear()
self.textEdit.insertPlainText(row)

def edit_input(self):
word_to_esp = {'gx': 'ĝ', 'cx': 'ĉ', 'hx': 'ĥ', 'jx': 'ĵ', 'ux':
'ŭ', 'sx': 'ŝ'}
user_input = self.lineEdit.text()
user_input = user_input.lower()
for i in word_to_esp:
if user_input.__contains__(i):
a = user_input.replace(i, word_to_esp[i])
return self.lineEdit.set(a)


if __name__ == "__main__":

app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor