Translater + module + tkinter

Joined
Jan 26, 2023
Messages
9
Reaction score
0
Good evening everyone ! I have case out of my league. I've made kind of dictionary English-Russian, with your help of course ! The heart of the matter I want to make exactly Dictionary of English Idioms, You can find there some idiom, provided it is not found, out there is opportunity to input it, and to pass kind of test with mark in the end of it. And now I have to wrap it into tkinter. I would appreciate if you help me for start, next I am going to do it myself.
__________________________

Onward and upward.

<<<Txt en>>>

The big time
Hit the jackpot
Make a bundle
go Dutch
Nest egg
At all cost
Break the bank
Crack of dawn
When pigs fly
Elephant in the room
Have a tiger by the tail
Lion's share of smth
Egghead
Couch potato
Eat one's words
Chew the fat
Hot potato
Take smth with a pinch of salt
Cry over split milk
Top dog
Be ahead of time
Pressed for time
In the blink of an eye
On the spur of the moment
Like clockwork
Around the clock
Lighting-fast
As right as rain
Huge
Bolt from the blue
A blessing in disguise
Break a leg!
Face like thunder
Snow white

<<<Txtru>>>

Большой успех
Срывать куш
Сделать кучу денег
Платить свою часть
Заначка
Любой ценой
Сильно потратится
С восходом солнца
Когда рак свиснет
Это очевидно
Бросать вызов судьбе
Львинная доля
Умник
Бездельник
Брать свои слова назад
Лясы точить
Актуальная тема
Не доверять
Горевать о не поправимом
Победитель
Опережать
Очень торопиться
В одно мгновение
С наскока
Без перебоя
Круглосуточно
Молниеносный
В полном порядке
Огромный
Как снег на голову
Хорошое дело, казавшееся на первый взгляд плохим
Удачи!
Мрачнее тучи
Белоснежка

<<<MODULE >>>
Python:
from random import*
import random


def read_file(file:str)->list:

    fail=open(file,'r', encoding='utf-8-sig')
    mas=[]
    for row in fail:
        if row.isdigit():
            mas.append(row.strip())
        else:
            mas.append(row.strip())
    fail.close()
    return mas

def save_to_file(mas:list,file:str):

    f=open(file,'w', encoding='utf-8-sig')
    for item in mas:
        f.write(item+'\n')
    f.close()

def input_word(e:list,r:list):
    n=int(input('what language_? 1 English, 2 Russian'))
    if int(n)==1:
        english=input('English:')
        e.append(english)
        russian=input('Russian:')
        r.append(russian)
    else:
        russian=input('Russian:')
        r.append(russian)
        english=input('English:')
        e.append(english)

    return e,r

def fix_e(name:str,e:list):
    v=e.count(name)
    v=input('enter word has to be fixed:')
    if v in name:
        fix_word=input('correction:')
        for n,i in enumerate(name):
            if i==v:
                name[n]=fix_word
                for j,n in zip(name,e):
                    print(f'{j} / {n}')
                #print('fixed:\n{0}'.format(name))

def fix_r(name:str,r:list):
    v=r.count(name)
    v=input('enter word has to be fixed:')
    if v in name:
        fix_word=input('correction:')
        for f,j in enumerate(name):
            if j==v:
                name[f]=fix_word
                for t,c in zip(name,r):
                    print(f'{t} / {c}')
                #print('fixed:\n{0}'.format(name))

def control_word(e:list,r:list):
    ru=0
    en=0
    try:
       
        for i in range(4):
            eng=list(map(str,e))
            eng=random.choice(eng)
            print(eng) 
            rus=list(map(str,r))

            answ=input('word:') 
           
       
            if answ in rus:
                print('right')
                en+=1
            if answ not in rus:
                print('wrong')
            ru+=1
       
        p=en/ru*100
        print(f'point is {p}')
        try:
            p=en/ru*100
        except:
            print("")
        if p<=59:
            mark="your mark is 2"
        elif p>=60 and p<=74: 
            mark="your mark is 3"
        elif p>=75 and p<=89:
            mark="your mark is 4"
        else:
            mark="your mark is 5"
        print(mark)
       
    except ZeroDivisionError:
                 
 
        return e,r


<<<Main sheet >>>

Python:
from Dictator import*


while True:
    print('----------------------------------------')
    print('\n0 read file\n1 input words\n2 save words to dictionary\n3 translate word/find word\n4 fix_word\n5 test')
    v=input('>>:')
    if v=='0':
        english=[]
        russian=[]
      
        english=read_file('eng_file.txt')
        russian=read_file('rus_file.txt')
        zipped=list(zip(english,russian))
        for e,n in zip(english,russian):
            print(f'{e} / {n}')
       
    elif v=='1':
        english,russian=input_word(english,russian)
        for t,v in zip(english,russian):
                print(f'{t} / {v}')
    elif v=='2':
         
        save_to_file(english,'eng_file.txt')
        save_to_file(russian,'rus_file.txt')
    elif v=='3':




        with open('eng_file.txt','r', encoding='utf-8-sig') as eng_file, open('rus_file.txt', 'r', encoding='utf-8-sig') as rus_file:
            eng = map(str.rstrip, eng_file)
            rus = map(str.rstrip, rus_file)
           

            data = dict(zip(eng, rus))
           
            n=input('what laguage? 1 Englis, 2 Russian')
            if int(n)==1:
                word =input('English ')
                if word in data.keys():
                    print(f'word: {word} is found: {data[word]}')
                if word not in data.keys():
                    print('word is not found')
                if word not in data.keys():
                    print('would you like to input the word to the dictionary?:1 yes,2 no')
                    c=input('')
                    if c=='1':
                           english,russian=input_word(english,russian)
                           for x,o in zip(english,russian): 
                               print(f'{x} / {o}')
                    elif c=='2':
                        break
            if int(n)==2: 
                with open('eng_file.txt','r', encoding='utf-8-sig') as name_file, open('rus_file.txt', 'r', encoding='utf-8-sig') as salary_file:
                    eng = map(str.rstrip, name_file)
                    rus = map(str.rstrip, salary_file)
                    data = dict(zip(rus, eng)) 
                    word =input('Russian')
                    if word in data.keys():
                            print(f'word: {word} is found: {data[word]}')
                    if word not in data.keys():
                            print('word is not found')
                    if word not in data.keys():
                            print('would you like to input the word to the dictionary?:1 yes,2 no')
                            c=input('')
                            if c=='1':
                                   english,russian=input_word(english,russian)
                                   for z,l in zip(english,russian):  
                                       print(f'{z} / {l}')
                            elif c=='2':
                                break
    elif v=='4':
        c=input('in which language the word should be corrected? 1 English,2 Russian ')
        try:
            if c=='1':
                fix_e(english,russian)
            if c=='2':
                fix_r(russian,english)
        except:
            print('Error')
    elif v=='5': 
        control_word(english,russian)

<<<<tkinter*>>>

Python:
from tkinter import*
from tkinter import ttk


c=0

def clicker(event):
 global c
 c+=1
 lbl.configure(text=c)

def clicker(event):
 global c
 if c>0:
  c-=1
 
  lbl.configure(text=c)
 
def entry_to_lable(event):
 lbl.configure(text=text)
 ent.delete(0,END)
def choice():
 text=var.get()
 ent.insert(END,text)
def new_window(ind:int):
 def tab_choice(ind:int):
  newwindow.title(text[ind])
 
 
 newwindow=Toplevel()
 tabs=ttk.Notebook(newwindow)
 texts=['1','2','3','4']
 tab=[]
 for i in range(len(texts)):
  tab.append('tab'+str(i))
  tab[i]=Frame(tabs)
  tabs.add(tab[i],text=text[i])
  tab[i].bind('<button 1>', tab_choice(i))
 tabs.grid(row=0,column=0)
 tabs.select[ind]
 newwindow.title(texts[ind])
 newwindow.mainloop()
window=Tk()
window.title('1 window')
#window.geometry('200×100')
m=Menu(window)
window.config(menu=m)
m1=Menu(m)
m.add_cascade(label='Tabs', menu=m1)
m1.add_command(label='Tabs1', accelerator='Command+A', command=lambda:new_window(0))
m1.add_command(label='Tabs2', accelerator='Command+B', command=lambda:new_window(1))
m1.add_command(label='Tabs3', accelerator='Command+C', command=lambda:new_window(2))
m1.add_command(label='Tabs4', accelerator='Command+D', command=lambda:new_window(3))

lbl=Label(window,text='.....', font='Arial 20')

btn=Button(window, text='Press',font='Arial 20', fg='black', bg='#32a852',width=30, height=5, relief=RAISED) #GROOVE,SUNKEN,RAISED .pack()

ent=Entry(window,fg='black', bg='#32a852' , width=30, justify=CENTER) #Text box


var=IntVar() #stringVar()
r1=Radiobutton(window, text='first', width=30, font='Arial 20', variable=var, value=1, command=choice )

r2=Radiobutton(window, text='Second', width=30, font='Arial 20', variable=var, value=2, command=choice )

btn.bind('<Button-1>', clicker) # 1 left 3 right #2 wheel. connection beetwen button and action
btn.bind('<Button-3>', clicker)  
ent.bind('<Return>', entry_to_lable) #Enter
btn.pack()
lbl.pack()
ent.pack()
r1.pack(side=LEFT) #from left to right
r2.pack(side=LEFT)

window.mainloop() # start the window
 
Joined
Dec 10, 2022
Messages
73
Reaction score
22
A few notes:
  • You should have a look into using classes.
  • When using tkinter you only need one mainloop
  • Using wildcard import (eg *) is bad practice. It could cause problems
  • Not really sure what the interface should look like. You are using tkinter windows and notebook
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,792
Messages
2,569,639
Members
45,352
Latest member
SherriePet

Latest Threads

Top