[Tkinter-discuss] What is wrong with this?

Mannequin* mannslists at invigorated.org
Sun Jan 21 14:44:10 CET 2007


Hi all,

I have this test (below). What I'm trying to do is when the user clicks 
on the '7' button, 7 will appear in the disabled entry widget. My 
problem is, when the script starts, it automatically throws '7' in to 
the entry widget, and nothing happens when the '7' button is clicked.

Might this be an issue where I have to use a StringVar, or is this just 
my bad logic?

Thanks!
-M.

-------------------------------------------------------------------------------------
#!/usr/bin/env python

from Tkinter import *

class SmallTest (Frame):
     def __init__ (self, parent = None):
         # Class 'constants'
         self.title = "SmallTest"

         # Set title and border width
         self.root = Tk ()
         self.root.title (self.title)
         self.root.config (borderwidth = 3)
         self.root.resizable (width = False, height = False)

         # Initialize Frame object
         Frame.__init__ (self, parent)
         self.pack (fill = 'both', expand = 'yes')

         # Populate the window
         self.place = 0
         self.create_widgets ()

     def create_widgets (self):
         # Create the main frame
         self.mainframe = Frame (self, borderwidth = 2)
         self.mainframe.pack (expand = 'yes', fill = 'both', side = TOP)

         # Create the display
         self.entryframe = Frame (self.mainframe, borderwidth = 2)
         self.entryframe.pack (expand = 'yes', fill = 'both', side = TOP)
         self.entry = Entry (self.entryframe, justify = RIGHT, state = 
DISABLED)
         self.entry.pack (expand = 'yes', fill = 'x', side = TOP)

         # Create the number and operator buttons
         self.topbuttonframe = Frame (self.mainframe, borderwidth = 2)
         self.topbuttonframe.pack (expand = 'yes', fill = 'both', side = 
TOP)
         self.button7 = Button (self.topbuttonframe, text = "7", width = 
2, command = self.buttonAction ('7'))
         self.button7.pack (expand = 'yes', fill = 'both', side = LEFT)

     def buttonAction (self, action = '+'):
         self.entry["state"] = NORMAL
         self.entry.insert (self.place, action)
         self.place = self.place + 1
         self.entry["state"] = DISABLED

if (__name__ == "__main__"):
     a = SmallTest ()
     a.mainloop ()
-------------------------------------------------------------------------------------


More information about the Tkinter-discuss mailing list