I'm getting "TypeError: unsupported operand type(s) for *: 'instance' and 'int'"

It looks as if I am not setting a correctly and it would be great if someone could assist me with my problem. Thanks!

#! /usr/bin/env python
from Tkinter import *
import tkMessageBox
tkMessageBox.showinfo("Text","Hello.  Tell me any whole number and I will tell you if it is even or odd.  You can even put in equations like 6 / 3!")
class GUIFramework(Frame):
    """This is the GUI"""
    
    def __init__(self,master=None):
        """Initialize yourself"""
        
        """Initialise the base class"""
        Frame.__init__(self,master)
        
        """Set the Window Title"""
        self.master.title("Type Some Text")
        
        """Display the main window"
        with a little bit of padding"""
        self.grid(padx=10,pady=10)
        self.CreateWidgets()
       
    def CreateWidgets(self):
        """Create all the widgets that we need"""
                
        """Create the Text"""
        self.lbText = Label(self, text="Enter Number:")
        self.lbText.grid(row=0, column=0)
        
        """Create the Entry, set it to be a bit wider"""
        self.enText = Entry(self)
        self.enText.grid(row=0, column=1, columnspan=3)
        
        self.btnDisplay = Button(self, text="Check", command=self.Display)
        self.btnDisplay.grid(row=0, column=4)
        global a
        a = self
        
    def Display(self):
        """Called when btnDisplay is clicked, displays the contents of self.enText"""
        global a
        if a > 0:
            if a % 2 == 0:
                tkMessageBox.showinfo("%s is an even number" % a)
            elif a % 2 == 1:
                tkMessageBox.showinfo("%s is an odd number" % a)
            else:
                tkMessageBox.showinfo("I don't understand the number, %s" % a)
        elif a < 0:
            a = a * -1
            if a % 2 == 0:
                tkMessageBox.showinfo("%s is an even number" % a)
            elif a % 2 == 1:
                tkMessageBox.showinfo("%s is an odd number" % a)
            else:
                tkMessageBox.showinfo("I don't understand the number, %s" % a)
        else:
            print "You did something wrong, try again."
if __name__ == "__main__":
    guiFrame = GUIFramework()
    guiFrame.mainloop()

The issue here is that you're using the operator * (which is obviously multiplication) to multiply your object GUIFramework with an int.

In the context of what you're trying to do, get the value of the field first. Refer to the TkInter documentation for more info.

If you don't want to read docs, you need to only change Display like so:

def Display(self):
        """Called when btnDisplay is clicked, displays the contents of self.enText"""
        a = int( self.enText.get() )
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.