Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #35670 > unrolled thread
| Started by | Verde Denim <tdldev@gmail.com> |
|---|---|
| First post | 2012-12-27 20:20 -0500 |
| Last post | 2012-12-28 21:03 -0500 |
| Articles | 4 — 3 participants |
Back to article view | Back to comp.lang.python
learning curve Verde Denim <tdldev@gmail.com> - 2012-12-27 20:20 -0500
Re: learning curve alex23 <wuwei23@gmail.com> - 2012-12-27 18:32 -0800
Re: learning curve Verde Denim <tdldev@gmail.com> - 2012-12-28 13:29 -0500
Re: learning curve Terry Reedy <tjreedy@udel.edu> - 2012-12-28 21:03 -0500
| From | Verde Denim <tdldev@gmail.com> |
|---|---|
| Date | 2012-12-27 20:20 -0500 |
| Subject | learning curve |
| Message-ID | <mailman.1379.1356660991.29569.python-list@python.org> |
Just getting into Py coding and not understanding why this code doesn't
seem to do anything -
# 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
[toc] | [next] | [standalone]
| From | alex23 <wuwei23@gmail.com> |
|---|---|
| Date | 2012-12-27 18:32 -0800 |
| Message-ID | <0b533176-5284-450d-aa8d-1e1ca9df1906@m4g2000pbd.googlegroups.com> |
| In reply to | #35670 |
On Dec 28, 11:20 am, Verde Denim <tdl...@gmail.com> wrote: > Just getting into Py coding and not understanding why this code doesn't > seem to do anything - Is that the sum total of your code? You're not showing any instantiation of your classes.
[toc] | [prev] | [next] | [standalone]
| From | Verde Denim <tdldev@gmail.com> |
|---|---|
| Date | 2012-12-28 13:29 -0500 |
| Message-ID | <mailman.1409.1356719335.29569.python-list@python.org> |
| In reply to | #35671 |
On 12/27/2012 09:32 PM, alex23 wrote: > On Dec 28, 11:20 am, Verde Denim <tdl...@gmail.com> wrote: >> Just getting into Py coding and not understanding why this code doesn't >> seem to do anything - > > Is that the sum total of your code? You're not showing any > instantiation of your classes. Yes, as a matter of fact, it is the example verbatim from the tutorial pages that I found. Apparently, it isn't the best example... Thanks for the heads up.
[toc] | [prev] | [next] | [standalone]
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Date | 2012-12-28 21:03 -0500 |
| Message-ID | <mailman.1418.1356746661.29569.python-list@python.org> |
| In reply to | #35671 |
On 12/28/2012 1:29 PM, Verde Denim wrote: > On 12/27/2012 09:32 PM, alex23 wrote: >> On Dec 28, 11:20 am, Verde Denim <tdl...@gmail.com> wrote: >>> Just getting into Py coding and not understanding why this code doesn't >>> seem to do anything - >> >> Is that the sum total of your code? You're not showing any >> instantiation of your classes. > Yes, as a matter of fact, it is the example verbatim from the tutorial > pages that I found. Apparently, it isn't the best example... Let us say that it was an example of how to write classes, with usage left as an exercise for the reader ;-) -- Terry Jan Reedy
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web