Re: learning curve

Discussion in 'Python' started by Terry Reedy, Dec 28, 2012.

  1. Terry Reedy

    Terry Reedy Guest

    On 12/27/2012 8:20 PM, Verde Denim wrote:
    > Just getting into Py coding and not understanding why this code doesn't
    > seem to do anything -


    Part of your 'learning curve' should be learning to write informative
    subjects lines. The above says almost nothing. For this I suggest
    "Problem with classes and tkinter". In this case, you specifically need
    to add the tkinter startup code; check the example in the manual. If you
    do add that, you code may run, but it may required advice with someone
    with tkinter expertise (and interest) beyond mind.

    Also, if you are just starting, I recommend you start with 3.3 unless
    you have a good reason to start with an older version. (IE, you need to
    use a third party library that only runs with 2.x.)

    > # File: dialog2.py
    > import dialog_handler
    >
    > class MyDialog(dialog_handler.Dialog):
    > def body(self, master):
    > Label(master, text="First:").grid(row=0)
    > Label(master, text="Second:").grid(row=1)
    > self.e1 = Entry(master)
    > self.e2 = Entry(master)
    > self.e1.grid(row=0, column=1)
    > self.e2.grid(row=1, column=1)
    > return self.e1 # initial focus
    >
    > def apply(self):
    > first = string.atoi(self.e1.get())
    > second = string.atoi(self.e2.get())
    > print first, second # or something
    >
    > # File: dialog_handler.py
    >
    > from Tkinter import *
    > import os
    >
    > class Dialog(Toplevel):
    >
    > def __init__(self, parent, title = None):
    > Toplevel.__init__(self, parent)
    > self.transient(parent)
    >
    > if title:
    > self.title(title)
    > self.parent = parent
    > self.result = None
    > body = Frame(self)
    > self.initial_focus = self.body(body)
    > body.pack(padx=5, pady=5)
    > self.buttonbox()
    > self.grab_set()
    >
    > if not self.initial_focus:
    > self.initial_focus = self
    >
    > self.protocol("WM_DELETE_WINDOW", self.cancel)
    > self.geometry("+%d+%d" % (parent.winfo_rootx()+50,
    > parent.winfo_rooty()+50))
    > self.initial_focus.focus_set()
    > self.wait_window(self)
    >
    > #
    > # construction hooks
    > def body(self, master):
    > # create dialog body. return widget that should have
    > # initial focus. this method should be overridden
    > pass
    >
    > def buttonbox(self):
    > # add standard button box. override if you don't want the
    > # standard buttons
    > box = Frame(self)
    >
    > w = Button(box, text="OK", width=10, command=self.ok,
    > default=ACTIVE)
    > w.pack(side=LEFT, padx=5, pady=5)
    > w = Button(box, text="Cancel", width=10,
    > command=self.cancel)
    > w.pack(side=LEFT, padx=5, pady=5)
    >
    > self.bind("<Return>", self.ok)
    > self.bind("<Escape>", self.cancel)
    >
    > box.pack()
    >
    > #
    > # standard button semantics
    > def ok(self, event=None):
    > if not self.validate():
    > self.initial_focus.focus_set() # put focus back
    > return
    > self.withdraw()
    > self.update_idletasks()
    > self.apply()
    > self.cancel()
    >
    > def cancel(self, event=None):
    > # put focus back to the parent window
    > self.parent.focus_set()
    > self.destroy()
    >
    > #
    > # command hooks
    > def validate(self):
    > return 1 # override
    >
    > def apply(self):
    > pass # override
    >



    --
    Terry Jan Reedy
     
    Terry Reedy, Dec 28, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeremy S.

    Learning Curve on 2.0

    Jeremy S., Sep 9, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    400
    clintonG
    Sep 10, 2005
  2. Jetus
    Replies:
    10
    Views:
    531
    D'Arcy J.M. Cain
    Apr 8, 2008
  3. M.-A. Lemburg
    Replies:
    3
    Views:
    317
    M.-A. Lemburg
    Apr 9, 2008
  4. Hicham Mouline
    Replies:
    2
    Views:
    383
    Jerry Coffin
    Sep 14, 2009
  5. Zach Dennis
    Replies:
    3
    Views:
    170
    Jim Weirich
    Jan 30, 2004
Loading...

Share This Page