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

  • Home
  • SEARCH
  • 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 6340769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:53:57+00:00 2026-05-24T19:53:57+00:00

I’m using Python’s Tkinter to create a GUI for a project i’m working on.

  • 0

I’m using Python’s Tkinter to create a GUI for a project i’m working on.

When I try to run part of the code though, I get this error:

Traceback (most recent call last):
  File "calculator.py", line 59, in <module>
    app = Application()
  File "calculator.py", line 28, in __init__
    self.create_widgets()
  File "calculator.py", line 45, in create_widgets
    self.special_chars.create_button(char, self.add_char_event(special_characters[char]))
  File "calculator.py", line 20, in create_button
    self.button_list += Button(self, text = txt, command = fcn)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/
lib-tk/Tkinter.py", line 1206, in cget
TypeError: cannot concatenate 'str' and 'int' objects

The problem is that I can’t find the file that the error message references; my python2.7/lib-tk folder only contains complied versions (.pyo and .pyc) of Tkinter.

Is there a way to figure out what’s going wrong?

Here’s the source of calculator.py

from Tkinter import *
from exp import full_eval
from maths import special_characters

class special_char_frame(LabelFrame):
    def __init__(self, master = None, text = 'Special Characters'):
        LabelFrame.__init__(self, master)
        self.grid()
        self.button_list = []
    def create_button(self, txt, fcn):
        self.button_list += Button(self, text = txt, command = fcn)
        self.button_list[-1].grid(row = 0)


class Application(Frame):
    def __init__(self, master = None):
        Frame.__init__(self, master)
        self.grid()
        self.create_widgets()
    def create_widgets(self):
        ## equation entry pane
        self.text_entry = Entry(self, width = 100)
        self.text_entry.grid(row = 0, column = 0)
        self.text_entry.bind('<KeyPress-Return>', self.calculate)
        ## result pane
        self.result = StringVar()
        self.result_label = Label(self, textvariable = self.result, wraplength = 815, justify = LEFT)
        self.result_label.grid(row = 1, column = 0, columnspan = 2, sticky = W)
        self.result.set('')
        ## calculate button
        self.calc_button = Button(self, text = 'Calculate', command = self.calculate)
        self.calc_button.grid(row = 0, column = 1)
        ## special character button pane
        self.special_chars = special_char_frame(self)
        for char in special_characters:
            self.special_chars.create_button(char, self.add_char_event(special_characters[char]))
        self.special_chars.grid(column = 0, columnspan = 2, row = 2)
    def calculate(self, event = None):
        try:
            self.result.set(full_eval(self.text_entry.get()))
        except Exception as error:
            raise
            #self.result.set(str(error))
        self.text_entry.select_range(0, END)
    def add_char_event(self, char):
        def add_char(self = self, event = None):
            self.text_entry.insert(INSERT, char)
        return add_char

app = Application()
app.master.title('Calculator')
app.mainloop()

full_eval is a function for evaluating mathematical expressions.

special_characters is a dict containing special characters and their explanations. For now it’s just special_characters = {'imaginary unit' : u'\u2148'}

  • 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-24T19:53:58+00:00Added an answer on May 24, 2026 at 7:53 pm

    Ok, so I missed this the first time, but the issue is actually that you are trying to add a Button to a list:

    self.button_list += Button(self, text = txt, command = fcn)
    

    If you simply wrap the Button in brackets, the error goes away (which makes sense because you are supposed to be able to add two lists):

    self.button_list += [Button(self, text = txt, command = fcn)]
    

    ORIGINAL ATTEMPT

    My guess:

    special_characters is a dictionary. It has key-value mappings where the values are ints. Then, when used in self.text_entry.insert(INSERT, char), text_entry is trying to insert an int into a str and causing the above error. The simple solution: wrap char with str in add_char.

    def add_char_event(self, char):
        def add_char(self = self, event = None):
            self.text_entry.insert(INSERT, str(char))
        return add_char
    

    Your other option is to wrap str around the special_characters lookup:

        for char in special_characters:
            self.special_chars.create_button(char,
                 self.add_char_event(str(special_characters[char])))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm making a simple page using Google Maps API 3. My first. One marker

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.