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()