Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #9834
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!feed.news.qwest.net!mpls-nntp-02.inet.qwest.net!newsfeed.kamp.net!newsfeed.kamp.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'arguments': 0.05; 'received:verizon.net': 0.07; 'reference:': 0.07; 'terry': 0.07; '__name__': 0.09; 'parameter.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'subject:Function': 0.09; 'tkinter': 0.09; 'gui': 0.13; 'wrote:': 0.15; '"__main__":': 0.16; 'functools': 0.16; 'reedy': 0.16; 'subject:function': 0.16; 'tk()': 0.16; 'tkinter,': 0.16; 'pm,': 0.16; 'def': 0.16; 'jan': 0.19; 'column': 0.22; 'header:In-Reply-To:1': 0.22; 'subject: -- ': 0.25; 'skip:b 20': 0.26; 'import': 0.29; 'partial': 0.29; 'second': 0.29; 'parent': 0.30; 'usage.': 0.30; 'class': 0.31; 'subject:?': 0.31; 'to:addr:python-list': 0.34; 'header:X -Complaints-To:1': 0.34; 'header:User-Agent:1': 0.34; 'there': 0.34; 'app': 0.35; 'function.': 0.35; 'uses': 0.35; 'functions.': 0.37; 'using': 0.37; 'received:org': 0.38; 'takes': 0.38; 'subject:: ': 0.38; 'program,': 0.39; 'header:Mime-Version:1': 0.39; 'ways': 0.39; 'skip:s 20': 0.39; 'to:addr:python.org': 0.39; 'skip:r 20': 0.40; 'subject:over': 0.84 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Terry Reedy <tjreedy@udel.edu> |
| Subject | Re: Partial Function Application -- Advantages over normal function? |
| Date | Mon, 18 Jul 2011 16:17:28 -0400 |
| References | <mailman.1208.1310984052.1164.python-list@python.org> <adc8083f-bfb4-4929-b267-e8280b13403a@t8g2000prm.googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Gmane-NNTP-Posting-Host | pool-74-109-121-73.phlapa.fios.verizon.net |
| User-Agent | Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.18) Gecko/20110616 Lightning/1.0b2 Thunderbird/3.1.11 |
| In-Reply-To | <adc8083f-bfb4-4929-b267-e8280b13403a@t8g2000prm.googlegroups.com> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1231.1311020265.1164.python-list@python.org> (permalink) |
| Lines | 48 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1311020265 news.xs4all.nl 23884 [2001:888:2000:d::a6]:46890 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:9834 |
Show key headers only | View raw
On 7/18/2011 3:23 PM, woooee wrote:
> Partial can be used in a GUI program, like Tkinter, to send arguments
> to functions. There are other ways to do that as well as using
> partial. The following program uses partial to send the color to the
> change_buttons function.
> from Tkinter import *
> from functools import partial
>
> class App:
> def __init__(self, parent):
> self.my_parent = parent
> self.my_parent.geometry("200x100+10+10")
>
> self.R = list()
> for ctr, color in enumerate(("Red", "Blue", "Green")):
> btn = Radiobutton(self.my_parent, text=color, value=ctr+1,
> command=partial(self.change_buttons, color))
> btn.grid(row = 2, column = ctr+1)
This is a nice illustration. For future reference: enumerate now takes a
start value as second parameter. Given as 1, you do not need to remember
to add 1 for each usage.
for ctr, color in enumerate(("Red", "Blue", "Green"),1):
btn = Radiobutton(self.my_parent, text=color, value=ctr,
command=partial(self.change_buttons, color))
btn.grid(row = 2, column = ctr)
> btn.deselect()
> self.R.append(btn)
> self.R[0].select()
> self.change_buttons("Red")
>
> def change_buttons(self, color):
> self.my_parent.configure(bg=color)
> for btn in self.R:
> btn.configure(bg=color)
>
> if __name__ == "__main__":
> root = Tk()
> root.title ("Color Option")
> app = App(root)
> root.mainloop()
--
Terry Jan Reedy
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Partial Function Application -- Advantages over normal function? Kurian Thayil <kurianmthayil@gmail.com> - 2011-07-18 15:43 +0530
Re: Partial Function Application -- Advantages over normal function? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-07-19 01:08 +1000
Re: Partial Function Application -- Advantages over normal function? woooee <woooee@gmail.com> - 2011-07-18 12:23 -0700
Re: Partial Function Application -- Advantages over normal function? Terry Reedy <tjreedy@udel.edu> - 2011-07-18 16:17 -0400
csiph-web