A Dangling Tk Entry

W. eWatson notvalid2 at sbcglobal.net
Tue Mar 10 16:52:30 CET 2009

	"Down, Fang! Down, boy. Down." -- Soupy Sales, Comedian, talking to 		his 
imaginary animal, circa 1960.

Thank you very much. One more quote before I continue. A favorite.

	"The trouble with most folks isn't their ignorance. It's knowin' so
  	many things that ain't so." by Josh Billings, a 19th century
  	humorist (and not Mark Twain).

I could quote my wife next, but I'll skip it. As I believe I've repeatedly 
said, (aren't those interesting words? Sort of sound huffy, don't they?), I 
am not the author of the code. If I didn't mention it before, I am not about 
to wholesale change his code for the purposes I have at hand, so I try to 
remain faithful to what was written. As far as taking your grid suggestions, 
I believe I did, very likely in the 2000 lines of father code (the author's 
original code.) For whatever reason, they didn't work. Yes, even I am as a 
lowly newcomer to Python and Tkinter have heard the eval story. Again, I do 
not want diversions while I'm adding to this program.

Just to be clear about what I'm adding, the program needed, IMHO, a 
configuration file. I've already added a menu item in other parts of the 
code to save it, and to initialize the 'global' values the author uses in 
IntVar_GUI. That's the alias here for Sentinel_GUI in the big program. Now I 
can proceed to initialize the "dialog" and others without using control 
variables. This config effort I could have skipped, but thought it's now or 
never. I have things to add to the program that are way more interesting 
than this, and will have big payoffs to the users (a closed group of about 
40 users).

Despite my "no messing with code technique" policy, I may have to take into 
consideration some of your changes here, and your follow up. And, yes, I 
think I can now begin to tune up my geometry knowledge of Tkinter.

So again, thanks for your help. (I hope you don't mind my repetition here.) 

r wrote:
> OK, here is a slightly cleaned up version of this horrible code. I did
> not change too much at one time for fear of confusing you. The main
> problem is you did not explicitly grid the entry like i told you
> earlier, and why you are using eval is beyond any measure of sanity...
> from Tkinter import *
> import tkSimpleDialog
> class IntVar_GUI:
>      def __init__(self, master):
>          self.master = master
>          master.title('Control Variable Fun')
>          self.frame = Frame(master, height=200, width=200,
> takefocus=1, highlightthickness=2, highlightcolor='blue')
>          self.frame.pack()
>          #self.frame.bind("<KeyPress>", self.HandleKey)
>          self.anumber = 123 # Want name and value to be configurable
>          menu = Menu(master)
>          master.config(menu=menu)
>          self.mainMenu = Menu(menu)
>          menu.add_cascade(label="My Menu",menu=self.mainMenu)
>          self.mainMenu.add_command(label="Enter Data",
> command=self.Set_Enter_Data)
>          self.mainMenu.add_command
> (label="Exit",underline=1,command=self.Quit)
>          self.Focus()
>      def Set_Enter_Data(self):
>          sdict = {"ok":False, "anumber":self.anumber}
>          dialog = Enter_Data_Dialog(self.master, sdict)
>          self.Focus()
>          print "Howdy, set data. Number is:", dialog.anumberVar.get()
>          print "dict:", dialog.sdict
>          if not dialog.sdict["ok"]:
>              return
>          try:
>              self.anumber = int(dialog.anumberVar.get())#why the heck
> where you using eval here?
>              print "OK"
>          except:
>              print "Not OK"
>              pass
>          print "self.anumber:", self.anumber
>      def Quit(self):
>          self.running = False
>          #self.master.quit()
>          self.master.destroy()
>      def Focus( self ):
>          self.frame.focus_set()
> class Enter_Data_Dialog(tkSimpleDialog.Dialog):
>      def __init__(self, parent, sdict):
>          self.sdict = sdict
>          tkSimpleDialog.Dialog.__init__(self, parent)
>      def body(self,master):
>          self.title("Set a Number Entry Dialog")
>          Label( master, text="Number ").grid(row=0, sticky=W)
>          self.anumberVar = StringVar()
>          entry = Entry(master, width=10, textvariable=self.anumberVar)
>          entry.grid(row=0, column=1) #i told you to explicitly grid a
> widget you want to call later
>          entry.insert(0,11)
>          self.anumberVar.set( "%d" % self.sdict["anumber"] )
>          return entry
>      def apply(self):
>          self.sdict["ok"] = True
> def Process():
>      root = Tk()
>      app = IntVar_GUI(root)
>      root.mainloop()
> if __name__ == "__main__":
>      Process()
> The next message i send will be a rewrite of this code in a proper
> Pythonic fashion, this frankly is a plate of spaghetti!

                                W. eWatson

              (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
               Obz Site:  39° 15' 7" N, 121° 2' 32" W, 2700 feet

                     Web Page: <www.speckledwithstars.net/>

More information about the Python-list mailing list