Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6779275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:21:58+00:00 2026-05-26T16:21:58+00:00

I have written a program in Tkinter (Python 2.7), a scrabblehelper in Norwegian which

  • 0

I have written a program in Tkinter (Python 2.7), a scrabblehelper in Norwegian which contains some special characters (æøå), which means my wordlist (ordliste) contains words with special characters.

When I run my function finnord(c*), it returns ‘cd’. I am using an entry.get() to get the word to put in my function.

My problem is with the encoding of entry.get(). I have local coding UTF-8, but I get an UniCodeError when I am writing any special characters in my entrybox and matching them to my wordliste.

Here is my output.

Warning (from warnings module):
  File "C:\pythonprog\scrabble\feud.py", line 46
if s not in liste and s in ordliste:
UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode -    
interpreting them as being unequal

When i write in my shell:

> ordinn.get()
u'k\xf8**e'
> ordinn.get().encode('utf-8')
'k\xc3\xb8**e'
> print ordinn.get()
kø**e
> print ordinn.get().encode('utf-8')
kø**e

Anyone knows why I can’t match ordinn.get() (entry) to my wordlist ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T16:21:59+00:00Added an answer on May 26, 2026 at 4:21 pm

    I can reproduce the error this way:

    % python
    Python 2.7.2+ (default, Oct  4 2011, 20:03:08) 
    [GCC 4.6.1] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 'k\xf8**e' in [u'k\xf8**e']
    __main__:1: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
    False
    

    So perhaps s is a str object, and liste or ordliste contains unicode, or (as eryksun points out in the comments) vice versa. The solution is to decode the str objects (most likely with the utf-8 codec) to make them unicode.

    If that does not help, please print out and post the output of

    print(repr(s))
    print(repr(liste))
    print(repr(ordliste))
    

    I believe the problem can be avoided by converting all strings to unicode.

    1. When you generate ordliste from norsk.txt, use
      codecs.open('norsk.txt','r','utf-8'):

      encoding = sys.stdin.encoding
      with codecs.open('norsk.txt','r','utf-8') as fil:
          ordliste = [line.rstrip(u'\n') for line in fil]
      
    2. Convert all user input to unicode as soon as possible:

      def get_unicode(widget):
          streng = widget.get()
          try:
              streng = streng.decode('utf-8')
          except UnicodeEncodeError:
              pass
          return streng
      

    So perhaps try this:

    import Tkinter as tk
    import tkMessageBox
    import codecs
    import itertools
    import sys
    
    alfabetet = (u"abcdefghijklmnopqrstuvwxyz"
                 u"\N{LATIN SMALL LETTER AE}"
                 u"\N{LATIN SMALL LETTER O WITH STROKE}"
                 u"\N{LATIN SMALL LETTER A WITH RING ABOVE}")
    
    encoding = sys.stdin.encoding
    with codecs.open('norsk.txt','r',encoding) as fil:
        ordliste = set(line.rstrip(u'\n') for line in fil)
    
    def get_unicode(widget):
        streng = widget.get()
        if isinstance(streng,str):
            streng = streng.decode('latin-1')
        return streng
    
    def siord():
        alfa=lagtabell()
        try:
            streng = get_unicode(ordinn)
            ordene=finnord(streng,alfa)
            if len(ordene) == 0:
                # There are no words that match
                tkMessageBox.showinfo('Dessverre..','Det er ingen ord som passer...')
            else:
                # Done: The words that fit the pattern
                tkMessageBox.showinfo('Ferdig',
                    'Ordene som passer er:\n'+ordene.encode('utf-8'))
        except Exception as err:
            # There has been a mistake .. Check your word
            print(repr(err))
            tkMessageBox.showerror('ERROR','Det har skjedd en feil.. Sjekk ordet ditt.')
    
    def finnord(streng,alfa): 
        liste = set()
        for substitution in itertools.permutations(alfa,streng.count(u'*')):
            s = streng
            for ch in substitution:
                s = s.replace(u'*',ch,1)
            if s in ordliste:
                liste.add(s)
        liste = [streng]+list(liste)
        return u','.join(liste)+u'.'
    
    def lagtabell():
        tinbox = get_unicode(bokstinn)
        if not tinbox.isalpha():
            alfa = alfabetet
        else:
            alfa = tinbox.lower()
        return alfa
    
    root = tk.Tk()
    root.title('FeudHjelper av Martin Skow Røed')
    root.geometry('400x250+450+200')
    # root.iconbitmap('data/ikon.ico')
    
    skrift1 = tk.Label(root,
                    text = '''\
    Velkommen til FeudHjelper. Skriv inn de bokstavene du har, og erstatt ukjente med *.
    F. eks: sl**ge
    Det er kun lov til å bruke tre stjerner, altså tre ukjente bokstaver.''',
                    font = ('Verdana',8), wraplength=350)
    skrift1.pack(pady = 5)
    
    ordinn = tk.StringVar(None)
    tekstboks = tk.Entry(root, textvariable = ordinn)
    tekstboks.pack(pady = 5)
    
    # What letters do you have? Eg "ahneki". Leave blank here if you want all the words.
    skrift2 = tk.Label(root, text = '''Hvilke bokstaver har du? F. eks "ahneki". La det være blankt her hvis du vil ha alle ordene.''',
                    font = ('Verdana',8), wraplength=350)
    skrift2.pack(pady = 10)
    
    bokstinn = tk.StringVar(None)
    tekstboks2 = tk.Entry(root, textvariable = bokstinn)
    tekstboks2.pack()
    
    knapp = tk.Button(text = 'Finn ord!', command = siord)
    knapp.pack(pady = 10)
    root.mainloop()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written this program, which sorts some ints using a functor: #include<iostream> #include<list>
I have written some sample program and DLL to learn the concept of DLL
I have written a Python program to find the carrier of a cell phone
I have written a program a.exe which launches another program I wrote, b.exe ,
I have written a program which analyzes a project's source code and reports various
I have written a program in c, that do some calculations then creates a
I have written a program which opens a file then displays line by line
I have written a program which triggers a relay switch on a serial port.
I have written a program to process some data written to disk in big-endian
I've written a simple GUI program in python using Tkinter. Let's call this program

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.