Please help me!

I have to make dictionary in py tkinter and i don't know how to do definition

this is my code:

from Tkinter import *

j=("slo", "ang", "nem")

def pretvori():
if(b.get()==j[0] and c.get()==j[1]):
slo_v_ang()
if(b.get()==j[0] and c.get()==j[2]):
slo_v_nem()
if(b.get()==j[1] and c.get()==j[0]):
ang_v_slo()
if(b.get()==j[1] and c.get()==j[2]):
ang_v_nem()
if(b.get()==j[2] and c.get()==j[0]):
nem_v_slo()
if(b.get()==j[2] and c.get()==j[1]):
nem_v_ang()

slo1=("ena","dva","tri","štiri","pet")
ang1=("one","two","three","four","five")
nem1=("eins","zwei","drei","vier","fünf")

def slo_v_ang():
if(a.get()==slo1[0] : s.set(str(ang1[0])))


okno=Tk()

okno.title('Slovar')

oznaka=Label(okno, text='Vnesi besedo')
oznaka.pack()

a=Entry(okno)
a.pack()

b=StringVar()
c=StringVar()

opti1=OptionMenu(okno, b, 'slo', 'ang', 'nem')
opti2=OptionMenu(okno, c, 'slo', 'ang', 'nem')

opti1.pack(fill=X)
opti2.pack(fill=X)

b.set('nem')
c.set('ang')

pret=Button(okno,text='Pretvori',command=pretvori)
pret.pack()

s=StringVar()
d=Label(okno,textvariable=s)
d.pack()

okno.mainloop()

Recommended Answers

All 10 Replies

Please use the CODE button.

Please help me!

I have to make dictionary in py tkinter and i don't know how to do definition

this is my code:

from Tkinter import *

j=("slo", "ang", "nem")

def pretvori():
if(b.get()==j[0] and c.get()==j[1]):
slo_v_ang()
if(b.get()==j[0] and c.get()==j[2]):
slo_v_nem()
if(b.get()==j[1] and c.get()==j[0]):
ang_v_slo()
if(b.get()==j[1] and c.get()==j[2]):
ang_v_nem()
if(b.get()==j[2] and c.get()==j[0]):
nem_v_slo()
if(b.get()==j[2] and c.get()==j[1]):
nem_v_ang()



slo1=("ena","dva","tri","štiri","pet")
ang1=("one","two","three","four","five")
nem1=("eins","zwei","drei","vier","fünf")

def slo_v_ang():
if(a.get()==slo1[0] : s.set(str(ang1[0])))






okno=Tk()

okno.title('Slovar')

oznaka=Label(okno, text='Vnesi besedo')
oznaka.pack()

a=Entry(okno)
a.pack()

b=StringVar()
c=StringVar()

opti1=OptionMenu(okno, b, 'slo', 'ang', 'nem')
opti2=OptionMenu(okno, c, 'slo', 'ang', 'nem')

opti1.pack(fill=X)
opti2.pack(fill=X)

b.set('nem')
c.set('ang')

pret=Button(okno,text='Pretvori',command=pretvori)
pret.pack()

s=StringVar()
d=Label(okno,textvariable=s)
d.pack()

okno.mainloop()

Okay, well what do you need the dictionary to be of? Also, directly copy and paste your code into the

encapsulation so the indentation is correct.

when i write in window for exaple one then i choose first button eng and second button slo then clik pretvori and the program write ena

So what you need is a way to convert a numeric word in any of the three languages to a word any of the other languages that means the same number. This suggests that you need to have a dictionary like this:

# hold number words in this order: (slovak, english, deutsch)
number_words = {
1:('ena','one','eins'), 2:('dva','two','zwei') ...}

Then all you have to do is "somehow" convert the input into a number value, look it up, and print out the appropriate translation.

You don't have to hold a triple (3-tuple) as the value in the number_words dictionary: It could be another dictionary using the language names as keys, or it could be a list, or whatever you want.

i don't know how to writte that translate

# -*- coding: cp1250 -*-
from Tkinter import *

j=("slo", "ang", "nem")

def pretvori():
    if(b.get()==j[0] and c.get()==j[1]):
       slo_v_ang()
    if(b.get()==j[0] and c.get()==j[2]):
        slo_v_nem()
    if(b.get()==j[1] and c.get()==j[0]):
        ang_v_slo()
    if(b.get()==j[1] and c.get()==j[2]):
        ang_v_nem()
    if(b.get()==j[2] and c.get()==j[0]):
        nem_v_slo()
    if(b.get()==j[2] and c.get()==j[1]):
        nem_v_ang()      

number_words = {1:('ena','one','eins'), 2:('dva','two','zwei'), 3:('tre','three','drei'), a:('avto','car','auto')}

def slo_v_ang():
   
# how can i call the number in definition

okno=Tk()

okno.title('Slovar')

oznaka=Label(okno, text='Vnesi besedo')
oznaka.pack()

a=Entry(okno)
a.pack()

b=StringVar()
c=StringVar()

opti1=OptionMenu(okno, b, 'slo', 'ang', 'nem')
opti2=OptionMenu(okno, c, 'slo', 'ang', 'nem')

opti1.pack(fill=X)
opti2.pack(fill=X)

b.set('nem')
c.set('ang')

pret=Button(okno,text='Pretvori',command=pretvori)
pret.pack()

s=StringVar()
d=Label(okno,textvariable=s)
d.pack()

okno.mainloop()

On line 7 (and the other "if' in function pretvori): What are variables b and c? Where declared, where defined? This must happen before the function is called. This function looks very difficult. Do you understand how to check the first two characters of a string? Like this:

somestring = 'string'
inputstring - 'str'
if somestring.startswith(inputstring[:2]):
  # the first two characters match
else:
 # they do not match

At line 24: I do not understand your question

b and c are buttons from which to which language do you translate
a is a window where you write your word for translate

we have to do with tkinter this task

from Tkinter import *

class App:
	def __init__(self,parent):
		
		f =Frame(parent)
		f.pack(padx=15,pady=15)
		
		Label(f,text='Vpisi besedo:').pack(side=TOP,padx=10,pady=10)
   		self.entry = Entry(f,text=" ").pack(side=TOP,padx=10,pady=10)
		
		self.button = Button(f, text="slo - ang",command=self.prevedi).pack(side=TOP,padx=10,pady=10)

		self.button = Button(f, text="ang - slo",command=self.prevedi1).pack(side=TOP,padx=10,pady=10)
		
		self.exit = Button(f, text="IZHOD", command=f.quit).pack()

	def prevedi(self):
		print "prevod"
	
	def prevedi1(self):
		print "test"


root = Tk()
root.title('SLOVAR')
app = App(root)

root.mainloop()

I don't knwo how to write definition for button that when you write for example dog and press button ang-slo taht translate into pes. Please help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.